| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/accelerators/accelerator_controller.h" | 5 #include "ash/accelerators/accelerator_controller.h" |
| 6 #include "ash/shell.h" | 6 #include "ash/shell.h" |
| 7 #include "ash/shell_window_ids.h" | 7 #include "ash/shell_window_ids.h" |
| 8 #include "ash/test/aura_shell_test_base.h" | 8 #include "ash/test/aura_shell_test_base.h" |
| 9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
| 10 #include "ui/aura/event.h" | 10 #include "ui/aura/event.h" |
| 11 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
| 12 #include "ui/aura/test/test_window_delegate.h" | 12 #include "ui/aura/test/test_window_delegate.h" |
| 13 #include "ui/aura/test/test_windows.h" | 13 #include "ui/aura/test/test_windows.h" |
| 14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 | 15 |
| 16 #if defined(USE_X11) | 16 #if defined(USE_X11) |
| 17 #include <X11/Xlib.h> | 17 #include <X11/Xlib.h> |
| 18 #include "ui/base/x/x11_util.h" | 18 #include "ui/base/x/x11_util.h" |
| 19 #endif | 19 #endif |
| 20 | 20 |
| 21 namespace aura_shell { | 21 namespace ash { |
| 22 namespace test { | 22 namespace test { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 class TestTarget : public ui::AcceleratorTarget { | 25 class TestTarget : public ui::AcceleratorTarget { |
| 26 public: | 26 public: |
| 27 TestTarget() : accelerator_pressed_count_(0) {}; | 27 TestTarget() : accelerator_pressed_count_(0) {}; |
| 28 virtual ~TestTarget() {}; | 28 virtual ~TestTarget() {}; |
| 29 | 29 |
| 30 int accelerator_pressed_count() const { | 30 int accelerator_pressed_count() const { |
| 31 return accelerator_pressed_count_; | 31 return accelerator_pressed_count_; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 // The non-registered accelerator is not processed. | 138 // The non-registered accelerator is not processed. |
| 139 const ui::Accelerator accelerator_b(ui::VKEY_B, false, false, false); | 139 const ui::Accelerator accelerator_b(ui::VKEY_B, false, false, false); |
| 140 EXPECT_FALSE(GetController()->Process(accelerator_b)); | 140 EXPECT_FALSE(GetController()->Process(accelerator_b)); |
| 141 } | 141 } |
| 142 | 142 |
| 143 #if defined(OS_WIN) || defined(USE_X11) | 143 #if defined(OS_WIN) || defined(USE_X11) |
| 144 TEST_F(AcceleratorControllerTest, ProcessOnce) { | 144 TEST_F(AcceleratorControllerTest, ProcessOnce) { |
| 145 // A focused window must exist for accelerators to be processed. | 145 // A focused window must exist for accelerators to be processed. |
| 146 aura::Window* default_container = | 146 aura::Window* default_container = |
| 147 aura_shell::Shell::GetInstance()->GetContainer( | 147 ash::Shell::GetInstance()->GetContainer( |
| 148 internal::kShellWindowId_DefaultContainer); | 148 internal::kShellWindowId_DefaultContainer); |
| 149 aura::Window* window = aura::test::CreateTestWindowWithDelegate( | 149 aura::Window* window = aura::test::CreateTestWindowWithDelegate( |
| 150 new aura::test::TestWindowDelegate, | 150 new aura::test::TestWindowDelegate, |
| 151 -1, | 151 -1, |
| 152 gfx::Rect(), | 152 gfx::Rect(), |
| 153 default_container); | 153 default_container); |
| 154 ActivateWindow(window); | 154 ActivateWindow(window); |
| 155 | 155 |
| 156 const ui::Accelerator accelerator_a(ui::VKEY_A, false, false, false); | 156 const ui::Accelerator accelerator_a(ui::VKEY_A, false, false, false); |
| 157 TestTarget target; | 157 TestTarget target; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 179 EXPECT_TRUE(aura::RootWindow::GetInstance()->GetDispatcher()->Dispatch( | 179 EXPECT_TRUE(aura::RootWindow::GetInstance()->GetDispatcher()->Dispatch( |
| 180 &key_event)); | 180 &key_event)); |
| 181 #endif | 181 #endif |
| 182 EXPECT_EQ(1, target.accelerator_pressed_count()); | 182 EXPECT_EQ(1, target.accelerator_pressed_count()); |
| 183 } | 183 } |
| 184 #endif | 184 #endif |
| 185 | 185 |
| 186 TEST_F(AcceleratorControllerTest, GlobalAccelerators) { | 186 TEST_F(AcceleratorControllerTest, GlobalAccelerators) { |
| 187 // A focused window must exist for accelerators to be processed. | 187 // A focused window must exist for accelerators to be processed. |
| 188 aura::Window* default_container = | 188 aura::Window* default_container = |
| 189 aura_shell::Shell::GetInstance()->GetContainer( | 189 ash::Shell::GetInstance()->GetContainer( |
| 190 internal::kShellWindowId_DefaultContainer); | 190 internal::kShellWindowId_DefaultContainer); |
| 191 aura::Window* window = aura::test::CreateTestWindowWithDelegate( | 191 aura::Window* window = aura::test::CreateTestWindowWithDelegate( |
| 192 new aura::test::TestWindowDelegate, | 192 new aura::test::TestWindowDelegate, |
| 193 -1, | 193 -1, |
| 194 gfx::Rect(), | 194 gfx::Rect(), |
| 195 default_container); | 195 default_container); |
| 196 ActivateWindow(window); | 196 ActivateWindow(window); |
| 197 | 197 |
| 198 // CycleBackward | 198 // CycleBackward |
| 199 EXPECT_TRUE(GetController()->Process( | 199 EXPECT_TRUE(GetController()->Process( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 215 #if !defined(OS_LINUX) | 215 #if !defined(OS_LINUX) |
| 216 // ToggleDesktopFullScreen (not implemented yet on Linux) | 216 // ToggleDesktopFullScreen (not implemented yet on Linux) |
| 217 EXPECT_TRUE(GetController()->Process( | 217 EXPECT_TRUE(GetController()->Process( |
| 218 ui::Accelerator(ui::VKEY_F11, false, true, false))); | 218 ui::Accelerator(ui::VKEY_F11, false, true, false))); |
| 219 #endif | 219 #endif |
| 220 #endif | 220 #endif |
| 221 } | 221 } |
| 222 | 222 |
| 223 TEST_F(AcceleratorControllerTest, HandleCycleWindow) { | 223 TEST_F(AcceleratorControllerTest, HandleCycleWindow) { |
| 224 aura::Window* default_container = | 224 aura::Window* default_container = |
| 225 aura_shell::Shell::GetInstance()->GetContainer( | 225 ash::Shell::GetInstance()->GetContainer( |
| 226 internal::kShellWindowId_DefaultContainer); | 226 internal::kShellWindowId_DefaultContainer); |
| 227 aura::Window* window0 = aura::test::CreateTestWindowWithDelegate( | 227 aura::Window* window0 = aura::test::CreateTestWindowWithDelegate( |
| 228 new aura::test::TestWindowDelegate, | 228 new aura::test::TestWindowDelegate, |
| 229 -1, | 229 -1, |
| 230 gfx::Rect(), | 230 gfx::Rect(), |
| 231 default_container); | 231 default_container); |
| 232 aura::Window* window1 = aura::test::CreateTestWindowWithDelegate( | 232 aura::Window* window1 = aura::test::CreateTestWindowWithDelegate( |
| 233 new aura::test::TestWindowDelegate, | 233 new aura::test::TestWindowDelegate, |
| 234 -1, | 234 -1, |
| 235 gfx::Rect(), | 235 gfx::Rect(), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 252 | 252 |
| 253 ui::Accelerator cycle_backward(ui::VKEY_TAB, true, false, true); | 253 ui::Accelerator cycle_backward(ui::VKEY_TAB, true, false, true); |
| 254 EXPECT_TRUE(GetController()->Process(cycle_backward)); | 254 EXPECT_TRUE(GetController()->Process(cycle_backward)); |
| 255 EXPECT_TRUE(IsActiveWindow(window2)); | 255 EXPECT_TRUE(IsActiveWindow(window2)); |
| 256 EXPECT_TRUE(GetController()->Process(cycle_backward)); | 256 EXPECT_TRUE(GetController()->Process(cycle_backward)); |
| 257 EXPECT_TRUE(IsActiveWindow(window1)); | 257 EXPECT_TRUE(IsActiveWindow(window1)); |
| 258 EXPECT_TRUE(GetController()->Process(cycle_backward)); | 258 EXPECT_TRUE(GetController()->Process(cycle_backward)); |
| 259 EXPECT_TRUE(IsActiveWindow(window0)); | 259 EXPECT_TRUE(IsActiveWindow(window0)); |
| 260 | 260 |
| 261 aura::Window* modal_container = | 261 aura::Window* modal_container = |
| 262 aura_shell::Shell::GetInstance()->GetContainer( | 262 ash::Shell::GetInstance()->GetContainer( |
| 263 internal::kShellWindowId_AlwaysOnTopContainer); | 263 internal::kShellWindowId_AlwaysOnTopContainer); |
| 264 aura::Window* modal_window = aura::test::CreateTestWindowWithDelegate( | 264 aura::Window* modal_window = aura::test::CreateTestWindowWithDelegate( |
| 265 new aura::test::TestWindowDelegate, | 265 new aura::test::TestWindowDelegate, |
| 266 -1, | 266 -1, |
| 267 gfx::Rect(), | 267 gfx::Rect(), |
| 268 modal_container); | 268 modal_container); |
| 269 | 269 |
| 270 // When the modal window is active, cycling window does not take effect. | 270 // When the modal window is active, cycling window does not take effect. |
| 271 ActivateWindow(modal_window); | 271 ActivateWindow(modal_window); |
| 272 EXPECT_TRUE(IsActiveWindow(modal_window)); | 272 EXPECT_TRUE(IsActiveWindow(modal_window)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 291 EXPECT_FALSE(IsActiveWindow(modal_window)); | 291 EXPECT_FALSE(IsActiveWindow(modal_window)); |
| 292 EXPECT_TRUE(GetController()->Process(cycle_backward)); | 292 EXPECT_TRUE(GetController()->Process(cycle_backward)); |
| 293 EXPECT_FALSE(IsActiveWindow(modal_window)); | 293 EXPECT_FALSE(IsActiveWindow(modal_window)); |
| 294 EXPECT_TRUE(GetController()->Process(cycle_backward)); | 294 EXPECT_TRUE(GetController()->Process(cycle_backward)); |
| 295 EXPECT_FALSE(IsActiveWindow(modal_window)); | 295 EXPECT_FALSE(IsActiveWindow(modal_window)); |
| 296 EXPECT_TRUE(GetController()->Process(cycle_backward)); | 296 EXPECT_TRUE(GetController()->Process(cycle_backward)); |
| 297 EXPECT_FALSE(IsActiveWindow(modal_window)); | 297 EXPECT_FALSE(IsActiveWindow(modal_window)); |
| 298 | 298 |
| 299 // When a screen lock window is visible, cycling window does not take effect. | 299 // When a screen lock window is visible, cycling window does not take effect. |
| 300 aura::Window* lock_screen_container = | 300 aura::Window* lock_screen_container = |
| 301 aura_shell::Shell::GetInstance()->GetContainer( | 301 ash::Shell::GetInstance()->GetContainer( |
| 302 internal::kShellWindowId_LockScreenContainer); | 302 internal::kShellWindowId_LockScreenContainer); |
| 303 aura::Window* lock_screen_window = aura::test::CreateTestWindowWithDelegate( | 303 aura::Window* lock_screen_window = aura::test::CreateTestWindowWithDelegate( |
| 304 new aura::test::TestWindowDelegate, | 304 new aura::test::TestWindowDelegate, |
| 305 -1, | 305 -1, |
| 306 gfx::Rect(), | 306 gfx::Rect(), |
| 307 lock_screen_container); | 307 lock_screen_container); |
| 308 | 308 |
| 309 lock_screen_window->Show(); | 309 lock_screen_window->Show(); |
| 310 EXPECT_FALSE(GetController()->Process(cycle_forward)); | 310 EXPECT_FALSE(GetController()->Process(cycle_forward)); |
| 311 EXPECT_FALSE(GetController()->Process(cycle_backward)); | 311 EXPECT_FALSE(GetController()->Process(cycle_backward)); |
| 312 | 312 |
| 313 // When a screen lock window is visible, cycling window does not take effect. | 313 // When a screen lock window is visible, cycling window does not take effect. |
| 314 // But otherwise, cycling window does take effect. | 314 // But otherwise, cycling window does take effect. |
| 315 aura::Window* lock_modal_container = | 315 aura::Window* lock_modal_container = |
| 316 aura_shell::Shell::GetInstance()->GetContainer( | 316 ash::Shell::GetInstance()->GetContainer( |
| 317 internal::kShellWindowId_LockModalContainer); | 317 internal::kShellWindowId_LockModalContainer); |
| 318 aura::Window* lock_modal_window = aura::test::CreateTestWindowWithDelegate( | 318 aura::Window* lock_modal_window = aura::test::CreateTestWindowWithDelegate( |
| 319 new aura::test::TestWindowDelegate, | 319 new aura::test::TestWindowDelegate, |
| 320 -1, | 320 -1, |
| 321 gfx::Rect(), | 321 gfx::Rect(), |
| 322 lock_modal_container); | 322 lock_modal_container); |
| 323 | 323 |
| 324 lock_modal_window->Show(); | 324 lock_modal_window->Show(); |
| 325 EXPECT_FALSE(GetController()->Process(cycle_forward)); | 325 EXPECT_FALSE(GetController()->Process(cycle_forward)); |
| 326 EXPECT_FALSE(GetController()->Process(cycle_backward)); | 326 EXPECT_FALSE(GetController()->Process(cycle_backward)); |
| 327 lock_screen_window->Hide(); | 327 lock_screen_window->Hide(); |
| 328 EXPECT_TRUE(GetController()->Process(cycle_forward)); | 328 EXPECT_TRUE(GetController()->Process(cycle_forward)); |
| 329 EXPECT_TRUE(GetController()->Process(cycle_backward)); | 329 EXPECT_TRUE(GetController()->Process(cycle_backward)); |
| 330 } | 330 } |
| 331 | 331 |
| 332 } // namespace test | 332 } // namespace test |
| 333 } // namespace aura_shell | 333 } // namespace ash |
| OLD | NEW |