| 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/session_state_delegate.h" | 9 #include "ash/session_state_delegate.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/shell_window_ids.h" | 11 #include "ash/shell_window_ids.h" |
| 12 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 13 #include "ash/test/test_shell_delegate.h" | 13 #include "ash/test/test_shell_delegate.h" |
| 14 #include "ash/wm/window_cycle_list.h" | 14 #include "ash/wm/window_cycle_list.h" |
| 15 #include "ash/wm/window_state.h" |
| 15 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
| 16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 17 #include "ui/aura/client/aura_constants.h" | 18 #include "ui/aura/client/aura_constants.h" |
| 18 #include "ui/aura/client/screen_position_client.h" | 19 #include "ui/aura/client/screen_position_client.h" |
| 19 #include "ui/aura/env.h" | 20 #include "ui/aura/env.h" |
| 20 #include "ui/aura/test/test_windows.h" | 21 #include "ui/aura/test/test_windows.h" |
| 21 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
| 22 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
| 23 #include "ui/gfx/screen.h" | 24 #include "ui/gfx/screen.h" |
| 24 | 25 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 EXPECT_FALSE(wm::IsActiveWindow(window0.get())); | 179 EXPECT_FALSE(wm::IsActiveWindow(window0.get())); |
| 179 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); | 180 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); |
| 180 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); | 181 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); |
| 181 } | 182 } |
| 182 | 183 |
| 183 // Cycles between a maximized and normal window. | 184 // Cycles between a maximized and normal window. |
| 184 TEST_F(WindowCycleControllerTest, MaximizedWindow) { | 185 TEST_F(WindowCycleControllerTest, MaximizedWindow) { |
| 185 // Create a couple of test windows. | 186 // Create a couple of test windows. |
| 186 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 187 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 187 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | 188 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
| 188 | 189 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
| 189 wm::MaximizeWindow(window1.get()); | 190 window1_state->Maximize(); |
| 190 wm::ActivateWindow(window1.get()); | 191 window1_state->Activate(); |
| 191 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | 192 EXPECT_TRUE(window1_state->IsActive()); |
| 192 | 193 |
| 193 // Rotate focus, this should move focus to window0. | 194 // Rotate focus, this should move focus to window0. |
| 194 WindowCycleController* controller = | 195 WindowCycleController* controller = |
| 195 Shell::GetInstance()->window_cycle_controller(); | 196 Shell::GetInstance()->window_cycle_controller(); |
| 196 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); | 197 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); |
| 197 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 198 EXPECT_TRUE(wm::GetWindowState(window0.get())->IsActive()); |
| 198 | 199 |
| 199 // One more time. | 200 // One more time. |
| 200 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); | 201 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); |
| 201 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | 202 EXPECT_TRUE(window1_state->IsActive()); |
| 202 } | 203 } |
| 203 | 204 |
| 204 // Cycles to a minimized window. | 205 // Cycles to a minimized window. |
| 205 TEST_F(WindowCycleControllerTest, Minimized) { | 206 TEST_F(WindowCycleControllerTest, Minimized) { |
| 206 // Create a couple of test windows. | 207 // Create a couple of test windows. |
| 207 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 208 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 208 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | 209 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
| 210 wm::WindowState* window0_state = wm::GetWindowState(window0.get()); |
| 211 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
| 209 | 212 |
| 210 wm::MinimizeWindow(window1.get()); | 213 window1_state->Minimize(); |
| 211 wm::ActivateWindow(window0.get()); | 214 window0_state->Activate(); |
| 212 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 215 EXPECT_TRUE(window0_state->IsActive()); |
| 213 | 216 |
| 214 // Rotate focus, this should move focus to window1 and unminimize it. | 217 // Rotate focus, this should move focus to window1 and unminimize it. |
| 215 WindowCycleController* controller = | 218 WindowCycleController* controller = |
| 216 Shell::GetInstance()->window_cycle_controller(); | 219 Shell::GetInstance()->window_cycle_controller(); |
| 217 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); | 220 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); |
| 218 EXPECT_FALSE(wm::IsWindowMinimized(window1.get())); | 221 EXPECT_FALSE(window1_state->IsMinimized()); |
| 219 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | 222 EXPECT_TRUE(window1_state->IsActive()); |
| 220 | 223 |
| 221 // One more time back to w0. | 224 // One more time back to w0. |
| 222 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); | 225 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); |
| 223 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 226 EXPECT_TRUE(window0_state->IsActive()); |
| 224 } | 227 } |
| 225 | 228 |
| 226 TEST_F(WindowCycleControllerTest, AlwaysOnTopWindow) { | 229 TEST_F(WindowCycleControllerTest, AlwaysOnTopWindow) { |
| 227 WindowCycleController* controller = | 230 WindowCycleController* controller = |
| 228 Shell::GetInstance()->window_cycle_controller(); | 231 Shell::GetInstance()->window_cycle_controller(); |
| 229 | 232 |
| 230 // Set up several windows to use to test cycling. | 233 // Set up several windows to use to test cycling. |
| 231 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 234 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 232 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | 235 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
| 233 | 236 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); | 436 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 434 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | 437 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 435 | 438 |
| 436 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); | 439 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 437 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 440 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 438 } | 441 } |
| 439 | 442 |
| 440 } // namespace | 443 } // namespace |
| 441 | 444 |
| 442 } // namespace ash | 445 } // namespace ash |
| OLD | NEW |