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/common/accelerators/accelerator_controller.h" | 5 #include "ash/common/accelerators/accelerator_controller.h" |
6 | 6 |
7 #include "ash/common/accelerators/accelerator_table.h" | 7 #include "ash/common/accelerators/accelerator_table.h" |
8 #include "ash/common/accessibility_delegate.h" | 8 #include "ash/common/accessibility_delegate.h" |
9 #include "ash/common/accessibility_types.h" | 9 #include "ash/common/accessibility_types.h" |
10 #include "ash/common/ash_switches.h" | 10 #include "ash/common/ash_switches.h" |
11 #include "ash/common/ime_control_delegate.h" | 11 #include "ash/common/ime_control_delegate.h" |
12 #include "ash/common/session/session_state_delegate.h" | 12 #include "ash/common/session/session_state_delegate.h" |
13 #include "ash/common/system/brightness_control_delegate.h" | 13 #include "ash/common/system/brightness_control_delegate.h" |
14 #include "ash/common/system/keyboard_brightness_control_delegate.h" | 14 #include "ash/common/system/keyboard_brightness_control_delegate.h" |
15 #include "ash/common/system/tray/system_tray_delegate.h" | 15 #include "ash/common/system/tray/system_tray_delegate.h" |
16 #include "ash/common/test/test_shelf_delegate.h" | 16 #include "ash/common/test/ash_test.h" |
17 #include "ash/common/wm/panels/panel_layout_manager.h" | 17 #include "ash/common/wm/panels/panel_layout_manager.h" |
18 #include "ash/common/wm/window_positioning_utils.h" | 18 #include "ash/common/wm/window_positioning_utils.h" |
19 #include "ash/common/wm/window_state.h" | 19 #include "ash/common/wm/window_state.h" |
20 #include "ash/common/wm/wm_event.h" | 20 #include "ash/common/wm/wm_event.h" |
21 #include "ash/common/wm_lookup.h" | |
21 #include "ash/common/wm_shell.h" | 22 #include "ash/common/wm_shell.h" |
22 #include "ash/common/wm_window.h" | 23 #include "ash/common/wm_window.h" |
24 #include "ash/mus/accelerators/accelerator_controller_registrar_test_api.h" | |
25 #include "ash/mus/bridge/wm_shell_mus_test_api.h" | |
26 #include "ash/mus/property_util.h" | |
27 #include "ash/mus/test/wm_test_base.h" | |
23 #include "ash/public/cpp/shell_window_ids.h" | 28 #include "ash/public/cpp/shell_window_ids.h" |
24 #include "ash/shell.h" | 29 #include "ash/root_window_controller.h" |
25 #include "ash/test/ash_test_base.h" | |
26 #include "ash/test/lock_state_controller_test_api.h" | |
27 #include "ash/test/test_screenshot_delegate.h" | |
28 #include "ash/test/test_session_state_animator.h" | |
29 #include "ash/wm/lock_state_controller.h" | |
30 #include "ash/wm/window_state_aura.h" | |
31 #include "ash/wm/window_util.h" | |
32 #include "base/command_line.h" | 30 #include "base/command_line.h" |
33 #include "base/test/user_action_tester.cc" | 31 #include "base/test/user_action_tester.cc" |
34 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | 32 #include "services/ui/public/interfaces/window_manager.mojom.h" |
35 #include "ui/app_list/presenter/app_list.h" | |
36 #include "ui/app_list/presenter/test/test_app_list_presenter.h" | |
37 #include "ui/aura/client/aura_constants.h" | 33 #include "ui/aura/client/aura_constants.h" |
38 #include "ui/aura/test/test_window_delegate.h" | |
39 #include "ui/aura/test/test_windows.h" | |
40 #include "ui/aura/window.h" | 34 #include "ui/aura/window.h" |
41 #include "ui/base/ime/chromeos/fake_ime_keyboard.h" | |
42 #include "ui/base/ime/chromeos/ime_keyboard.h" | |
43 #include "ui/base/ime/chromeos/input_method_manager.h" | |
44 #include "ui/base/ime/chromeos/mock_input_method_manager.h" | |
45 #include "ui/display/manager/display_manager.h" | |
46 #include "ui/display/screen.h" | |
47 #include "ui/events/event.h" | 35 #include "ui/events/event.h" |
48 #include "ui/events/event_processor.h" | 36 #include "ui/events/event_processor.h" |
49 #include "ui/events/test/event_generator.h" | 37 #include "ui/events/test/event_generator.h" |
50 #include "ui/message_center/message_center.h" | 38 #include "ui/message_center/message_center.h" |
51 #include "ui/views/widget/widget.h" | 39 #include "ui/views/widget/widget.h" |
52 | 40 |
53 #if defined(USE_X11) | 41 #if defined(USE_X11) |
54 #include <X11/Xlib.h> | 42 #include <X11/Xlib.h> |
55 #include "ui/events/test/events_test_utils_x11.h" | 43 #include "ui/events/test/events_test_utils_x11.h" |
56 #endif | 44 #endif |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 ++accelerator_repeat_count_; | 186 ++accelerator_repeat_count_; |
199 else | 187 else |
200 ++accelerator_pressed_count_; | 188 ++accelerator_pressed_count_; |
201 return true; | 189 return true; |
202 } | 190 } |
203 | 191 |
204 bool TestTarget::CanHandleAccelerators() const { | 192 bool TestTarget::CanHandleAccelerators() const { |
205 return true; | 193 return true; |
206 } | 194 } |
207 | 195 |
196 void ProcessAccelerator(ui::KeyboardCode key_code, int flags) { | |
197 const ui::Accelerator accelerator(key_code, flags); | |
198 if (!WmShell::Get()->accelerator_controller()->IsRegistered(accelerator)) | |
199 return; | |
200 | |
201 mus::AcceleratorControllerRegistrarTestApi().ProcessAccelerator(accelerator); | |
202 } | |
203 | |
208 } // namespace | 204 } // namespace |
209 | 205 |
210 class AcceleratorControllerTest : public test::AshTestBase { | 206 class AcceleratorControllerTest : public mus::WmTestBase { |
211 public: | 207 public: |
212 AcceleratorControllerTest() {} | 208 AcceleratorControllerTest() {} |
213 ~AcceleratorControllerTest() override {} | 209 ~AcceleratorControllerTest() override {} |
214 | 210 |
215 protected: | 211 protected: |
216 static AcceleratorController* GetController(); | 212 static AcceleratorController* GetController(); |
217 | 213 |
218 static bool ProcessInController(const ui::Accelerator& accelerator) { | 214 static bool ProcessInController(const ui::Accelerator& accelerator) { |
219 if (accelerator.type() == ui::ET_KEY_RELEASED) { | 215 if (accelerator.type() == ui::ET_KEY_RELEASED) { |
220 // If the |accelerator| should trigger on release, then we store the | 216 // If the |accelerator| should trigger on release, then we store the |
(...skipping 27 matching lines...) Expand all Loading... | |
248 static void SimulateTimerExpired(ExitWarningHandler* ewh) { | 244 static void SimulateTimerExpired(ExitWarningHandler* ewh) { |
249 ewh->TimerAction(); | 245 ewh->TimerAction(); |
250 } | 246 } |
251 static bool is_ui_shown(ExitWarningHandler* ewh) { return !!ewh->widget_; } | 247 static bool is_ui_shown(ExitWarningHandler* ewh) { return !!ewh->widget_; } |
252 static bool is_idle(ExitWarningHandler* ewh) { | 248 static bool is_idle(ExitWarningHandler* ewh) { |
253 return ewh->state_ == ExitWarningHandler::IDLE; | 249 return ewh->state_ == ExitWarningHandler::IDLE; |
254 } | 250 } |
255 static bool is_exiting(ExitWarningHandler* ewh) { | 251 static bool is_exiting(ExitWarningHandler* ewh) { |
256 return ewh->state_ == ExitWarningHandler::EXITING; | 252 return ewh->state_ == ExitWarningHandler::EXITING; |
257 } | 253 } |
258 aura::Window* CreatePanel() { | 254 // TODO: needs support for TestShelfDelegate: http://crbug.com/632208. |
259 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( | 255 /* |
260 NULL, ui::wm::WINDOW_TYPE_PANEL, 0, gfx::Rect(5, 5, 20, 20)); | 256 ui::Window* CreatePanel() { |
261 WmWindow* wm_window = WmWindow::Get(window); | 257 ui::Window* window = CreateTestWindow( |
262 test::TestShelfDelegate::instance()->AddShelfItem(wm_window); | 258 gfx::Rect(5, 5, 20, 20), |
263 PanelLayoutManager::Get(wm_window)->Relayout(); | 259 ui::wm::WINDOW_TYPE_PANEL); |
260 test::TestShelfDelegate* shelf_delegate = | |
261 test::TestShelfDelegate::instance(); | |
262 shelf_delegate->AddShelfItem(window); | |
263 PanelLayoutManager* manager = | |
264 PanelLayoutManager::Get(WmWindow::Get(window)); | |
265 manager->Relayout(); | |
264 return window; | 266 return window; |
265 } | 267 } |
268 */ | |
266 | 269 |
267 void SetBrightnessControlDelegate( | 270 void SetBrightnessControlDelegate( |
268 std::unique_ptr<BrightnessControlDelegate> delegate) { | 271 std::unique_ptr<BrightnessControlDelegate> delegate) { |
269 WmShell::Get()->brightness_control_delegate_ = std::move(delegate); | 272 WmShell::Get()->brightness_control_delegate_ = std::move(delegate); |
270 } | 273 } |
271 | 274 |
272 void SetKeyboardBrightnessControlDelegate( | 275 void SetKeyboardBrightnessControlDelegate( |
273 std::unique_ptr<KeyboardBrightnessControlDelegate> delegate) { | 276 std::unique_ptr<KeyboardBrightnessControlDelegate> delegate) { |
274 WmShell::Get()->keyboard_brightness_control_delegate_ = std::move(delegate); | 277 WmShell::Get()->keyboard_brightness_control_delegate_ = std::move(delegate); |
275 } | 278 } |
276 | 279 |
277 private: | 280 private: |
278 DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest); | 281 DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest); |
279 }; | 282 }; |
280 | 283 |
281 AcceleratorController* AcceleratorControllerTest::GetController() { | 284 AcceleratorController* AcceleratorControllerTest::GetController() { |
282 return WmShell::Get()->accelerator_controller(); | 285 return WmShell::Get()->accelerator_controller(); |
283 } | 286 } |
284 | 287 |
288 #if !defined(OS_WIN) | |
285 // Double press of exit shortcut => exiting | 289 // Double press of exit shortcut => exiting |
286 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestDoublePress) { | 290 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestDoublePress) { |
287 ui::Accelerator press(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN); | 291 ui::Accelerator press(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN); |
288 ui::Accelerator release(press); | 292 ui::Accelerator release(press); |
289 release.set_type(ui::ET_KEY_RELEASED); | 293 release.set_type(ui::ET_KEY_RELEASED); |
290 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest(); | 294 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest(); |
291 ASSERT_TRUE(ewh); | 295 ASSERT_TRUE(ewh); |
292 StubForTest(ewh); | 296 StubForTest(ewh); |
293 EXPECT_TRUE(is_idle(ewh)); | 297 EXPECT_TRUE(is_idle(ewh)); |
294 EXPECT_FALSE(is_ui_shown(ewh)); | 298 EXPECT_FALSE(is_ui_shown(ewh)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 ASSERT_TRUE(ewh); | 334 ASSERT_TRUE(ewh); |
331 StubForTest(ewh); | 335 StubForTest(ewh); |
332 | 336 |
333 // Trigger once to show the bubble. | 337 // Trigger once to show the bubble. |
334 ewh->HandleAccelerator(); | 338 ewh->HandleAccelerator(); |
335 EXPECT_FALSE(is_idle(ewh)); | 339 EXPECT_FALSE(is_idle(ewh)); |
336 EXPECT_TRUE(is_ui_shown(ewh)); | 340 EXPECT_TRUE(is_ui_shown(ewh)); |
337 | 341 |
338 // Exit ash and there should be no crash | 342 // Exit ash and there should be no crash |
339 } | 343 } |
344 #endif // !defined(OS_WIN) | |
340 | 345 |
341 TEST_F(AcceleratorControllerTest, Register) { | 346 TEST_F(AcceleratorControllerTest, Register) { |
342 TestTarget target; | 347 TestTarget target; |
343 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 348 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
344 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | 349 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
345 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); | 350 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); |
346 const ui::Accelerator accelerator_d(ui::VKEY_D, ui::EF_NONE); | 351 const ui::Accelerator accelerator_d(ui::VKEY_D, ui::EF_NONE); |
347 | 352 |
348 GetController()->Register( | 353 GetController()->Register( |
349 {accelerator_a, accelerator_b, accelerator_c, accelerator_d}, &target); | 354 {accelerator_a, accelerator_b, accelerator_c, accelerator_d}, &target); |
350 | 355 |
351 // The registered accelerators are processed. | 356 // The registered accelerators are processed. |
352 EXPECT_TRUE(ProcessInController(accelerator_a)); | 357 EXPECT_TRUE(ProcessInController(accelerator_a)); |
353 EXPECT_TRUE(ProcessInController(accelerator_b)); | 358 EXPECT_TRUE(ProcessInController(accelerator_b)); |
354 EXPECT_TRUE(ProcessInController(accelerator_c)); | 359 EXPECT_TRUE(ProcessInController(accelerator_c)); |
355 EXPECT_TRUE(ProcessInController(accelerator_d)); | 360 EXPECT_TRUE(ProcessInController(accelerator_d)); |
356 EXPECT_EQ(4, target.accelerator_pressed_count()); | 361 EXPECT_EQ(4, target.accelerator_pressed_count()); |
357 } | 362 } |
358 | 363 |
359 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { | 364 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { |
360 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 365 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
361 TestTarget target1; | 366 TestTarget target1; |
362 GetController()->Register({accelerator_a}, &target1); | 367 GetController()->Register({accelerator_a}, &target1); |
368 | |
363 TestTarget target2; | 369 TestTarget target2; |
364 GetController()->Register({accelerator_a}, &target2); | 370 GetController()->Register({accelerator_a}, &target2); |
365 | 371 |
366 // If multiple targets are registered with the same accelerator, the target | 372 // If multiple targets are registered with the same accelerator, the target |
367 // registered later processes the accelerator. | 373 // registered later processes the accelerator. |
368 EXPECT_TRUE(ProcessInController(accelerator_a)); | 374 EXPECT_TRUE(ProcessInController(accelerator_a)); |
369 EXPECT_EQ(0, target1.accelerator_pressed_count()); | 375 EXPECT_EQ(0, target1.accelerator_pressed_count()); |
370 EXPECT_EQ(1, target2.accelerator_pressed_count()); | 376 EXPECT_EQ(1, target2.accelerator_pressed_count()); |
371 } | 377 } |
372 | 378 |
373 TEST_F(AcceleratorControllerTest, Unregister) { | 379 TEST_F(AcceleratorControllerTest, Unregister) { |
380 TestTarget target; | |
374 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 381 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
375 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | 382 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
376 TestTarget target; | |
377 GetController()->Register({accelerator_a, accelerator_b}, &target); | 383 GetController()->Register({accelerator_a, accelerator_b}, &target); |
378 | 384 |
379 // Unregistering a different accelerator does not affect the other | 385 // Unregistering a different accelerator does not affect the other |
380 // accelerator. | 386 // accelerator. |
381 GetController()->Unregister(accelerator_b, &target); | 387 GetController()->Unregister(accelerator_b, &target); |
382 EXPECT_TRUE(ProcessInController(accelerator_a)); | 388 EXPECT_TRUE(ProcessInController(accelerator_a)); |
383 EXPECT_EQ(1, target.accelerator_pressed_count()); | 389 EXPECT_EQ(1, target.accelerator_pressed_count()); |
384 | 390 |
385 // The unregistered accelerator is no longer processed. | 391 // The unregistered accelerator is no longer processed. |
386 target.reset(); | 392 target.reset(); |
387 GetController()->Unregister(accelerator_a, &target); | 393 GetController()->Unregister(accelerator_a, &target); |
388 EXPECT_FALSE(ProcessInController(accelerator_a)); | 394 EXPECT_FALSE(ProcessInController(accelerator_a)); |
389 EXPECT_EQ(0, target.accelerator_pressed_count()); | 395 EXPECT_EQ(0, target.accelerator_pressed_count()); |
390 } | 396 } |
391 | 397 |
392 TEST_F(AcceleratorControllerTest, UnregisterAll) { | 398 TEST_F(AcceleratorControllerTest, UnregisterAll) { |
399 TestTarget target1; | |
393 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 400 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
394 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | 401 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
395 TestTarget target1; | |
396 GetController()->Register({accelerator_a, accelerator_b}, &target1); | 402 GetController()->Register({accelerator_a, accelerator_b}, &target1); |
397 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); | 403 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); |
398 TestTarget target2; | 404 TestTarget target2; |
399 GetController()->Register({accelerator_c}, &target2); | 405 GetController()->Register({accelerator_c}, &target2); |
400 GetController()->UnregisterAll(&target1); | 406 GetController()->UnregisterAll(&target1); |
401 | 407 |
402 // All the accelerators registered for |target1| are no longer processed. | 408 // All the accelerators registered for |target1| are no longer processed. |
403 EXPECT_FALSE(ProcessInController(accelerator_a)); | 409 EXPECT_FALSE(ProcessInController(accelerator_a)); |
404 EXPECT_FALSE(ProcessInController(accelerator_b)); | 410 EXPECT_FALSE(ProcessInController(accelerator_b)); |
405 EXPECT_EQ(0, target1.accelerator_pressed_count()); | 411 EXPECT_EQ(0, target1.accelerator_pressed_count()); |
(...skipping 22 matching lines...) Expand all Loading... | |
428 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN); | 434 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN); |
429 TestTarget target; | 435 TestTarget target; |
430 GetController()->Register({accelerator_a}, &target); | 436 GetController()->Register({accelerator_a}, &target); |
431 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); | 437 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); |
432 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); | 438 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); |
433 GetController()->UnregisterAll(&target); | 439 GetController()->UnregisterAll(&target); |
434 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); | 440 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); |
435 } | 441 } |
436 | 442 |
437 TEST_F(AcceleratorControllerTest, WindowSnap) { | 443 TEST_F(AcceleratorControllerTest, WindowSnap) { |
438 std::unique_ptr<aura::Window> window( | 444 aura::Window* aura_window = CreateTestWindow(gfx::Rect(5, 5, 20, 20)); |
439 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 445 WmWindow* window = WmWindow::Get(aura_window); |
440 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 446 wm::WindowState* window_state = window->GetWindowState(); |
441 | 447 |
442 window_state->Activate(); | 448 window_state->Activate(); |
443 | 449 |
444 { | 450 { |
445 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | 451 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_LEFT); |
446 gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( | 452 gfx::Rect expected_bounds = |
447 WmWindow::Get(window.get())); | 453 wm::GetDefaultLeftSnappedWindowBoundsInParent(window); |
448 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); | 454 EXPECT_EQ(expected_bounds.ToString(), window->GetBounds().ToString()); |
449 } | 455 } |
450 { | 456 { |
451 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | 457 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_RIGHT); |
452 gfx::Rect expected_bounds = wm::GetDefaultRightSnappedWindowBoundsInParent( | 458 gfx::Rect expected_bounds = |
453 WmWindow::Get(window.get())); | 459 wm::GetDefaultRightSnappedWindowBoundsInParent(window); |
454 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); | 460 EXPECT_EQ(expected_bounds.ToString(), window->GetBounds().ToString()); |
455 } | 461 } |
456 { | 462 { |
457 gfx::Rect normal_bounds = window_state->GetRestoreBoundsInParent(); | 463 gfx::Rect normal_bounds = window_state->GetRestoreBoundsInParent(); |
458 | 464 |
459 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); | 465 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); |
460 EXPECT_TRUE(window_state->IsMaximized()); | 466 EXPECT_TRUE(window_state->IsMaximized()); |
461 EXPECT_NE(normal_bounds.ToString(), window->bounds().ToString()); | 467 EXPECT_NE(normal_bounds.ToString(), window->GetBounds().ToString()); |
462 | 468 |
463 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); | 469 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); |
464 EXPECT_FALSE(window_state->IsMaximized()); | 470 EXPECT_FALSE(window_state->IsMaximized()); |
465 // Window gets restored to its restore bounds since side-maximized state | 471 // Window gets restored to its restore bounds since side-maximized state |
466 // is treated as a "maximized" state. | 472 // is treated as a "maximized" state. |
467 EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString()); | 473 EXPECT_EQ(normal_bounds.ToString(), window->GetBounds().ToString()); |
468 | 474 |
469 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); | 475 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); |
470 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | 476 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_LEFT); |
471 EXPECT_FALSE(window_state->IsMaximized()); | 477 EXPECT_FALSE(window_state->IsMaximized()); |
472 | 478 |
473 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); | 479 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); |
474 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | 480 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_RIGHT); |
475 EXPECT_FALSE(window_state->IsMaximized()); | 481 EXPECT_FALSE(window_state->IsMaximized()); |
476 | 482 |
477 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); | 483 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); |
478 EXPECT_TRUE(window_state->IsMaximized()); | 484 EXPECT_TRUE(window_state->IsMaximized()); |
479 GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE); | 485 GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE); |
480 EXPECT_FALSE(window_state->IsMaximized()); | 486 EXPECT_FALSE(window_state->IsMaximized()); |
481 EXPECT_TRUE(window_state->IsMinimized()); | 487 EXPECT_TRUE(window_state->IsMinimized()); |
482 window_state->Restore(); | 488 window_state->Restore(); |
483 window_state->Activate(); | 489 window_state->Activate(); |
484 } | 490 } |
485 { | 491 { |
486 GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE); | 492 GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE); |
487 EXPECT_TRUE(window_state->IsMinimized()); | 493 EXPECT_TRUE(window_state->IsMinimized()); |
488 } | 494 } |
489 } | 495 } |
490 | 496 |
491 // Tests that when window docking is disabled, only snapping windows works. | 497 // Tests that window snapping works. |
492 TEST_F(AcceleratorControllerTest, WindowSnapWithoutDocking) { | 498 TEST_F(AcceleratorControllerTest, WindowSnapWithoutDocking) { |
493 ASSERT_FALSE(ash::switches::DockedWindowsEnabled()); | 499 WmWindow* window = WmWindow::Get(CreateTestWindow(gfx::Rect(5, 5, 20, 20))); |
494 std::unique_ptr<aura::Window> window( | 500 wm::WindowState* window_state = window->GetWindowState(); |
495 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
496 | |
497 wm::WindowState* window_state = wm::GetWindowState(window.get()); | |
498 window_state->Activate(); | 501 window_state->Activate(); |
499 | 502 |
500 // Snap right. | 503 // Snap right. |
501 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | 504 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_RIGHT); |
502 gfx::Rect normal_bounds = window_state->GetRestoreBoundsInParent(); | 505 gfx::Rect normal_bounds = window_state->GetRestoreBoundsInParent(); |
503 gfx::Rect expected_bounds = wm::GetDefaultRightSnappedWindowBoundsInParent( | 506 gfx::Rect expected_bounds = |
504 WmWindow::Get(window.get())); | 507 wm::GetDefaultRightSnappedWindowBoundsInParent(window); |
505 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); | 508 EXPECT_EQ(expected_bounds.ToString(), window->GetBounds().ToString()); |
506 EXPECT_TRUE(window_state->IsSnapped()); | 509 EXPECT_TRUE(window_state->IsSnapped()); |
507 // Snap right again ->> becomes normal. | 510 // Snap right again ->> becomes normal. |
508 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | 511 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_RIGHT); |
509 EXPECT_TRUE(window_state->IsNormalStateType()); | 512 EXPECT_TRUE(window_state->IsNormalStateType()); |
510 EXPECT_FALSE(window_state->IsDocked()); | 513 EXPECT_EQ(normal_bounds.ToString(), window->GetBounds().ToString()); |
511 EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString()); | |
512 // Snap right. | 514 // Snap right. |
513 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | 515 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_RIGHT); |
514 EXPECT_TRUE(window_state->IsSnapped()); | 516 EXPECT_TRUE(window_state->IsSnapped()); |
515 EXPECT_FALSE(window_state->IsDocked()); | |
516 // Snap left. | 517 // Snap left. |
517 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | 518 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_LEFT); |
518 EXPECT_TRUE(window_state->IsSnapped()); | 519 EXPECT_TRUE(window_state->IsSnapped()); |
519 EXPECT_FALSE(window_state->IsDocked()); | 520 expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent(window); |
520 expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( | 521 EXPECT_EQ(expected_bounds.ToString(), window->GetBounds().ToString()); |
521 WmWindow::Get(window.get())); | |
522 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); | |
523 // Snap left again ->> becomes normal. | 522 // Snap left again ->> becomes normal. |
524 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | 523 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_LEFT); |
525 EXPECT_TRUE(window_state->IsNormalStateType()); | 524 EXPECT_TRUE(window_state->IsNormalStateType()); |
526 EXPECT_FALSE(window_state->IsDocked()); | 525 EXPECT_EQ(normal_bounds.ToString(), window->GetBounds().ToString()); |
527 EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString()); | |
528 } | 526 } |
529 | 527 |
530 // Test class used for testing docked windows. | 528 // This is commented out for two reasons: |
531 class EnabledDockedWindowsAcceleratorControllerTest | 529 // . http://crbug.com/630683: ash doesn't see all key events. |
532 : public AcceleratorControllerTest { | 530 // . http://crbug.com/615033: EventGenerator doesn't work with ash. That can be |
oshima
2017/02/23 02:21:02
you meant "mash" ?
afakhry
2017/02/23 18:08:53
I didn't make these changes. I think rebasing didn
| |
533 public: | 531 // worked around for the test, but no point until we decide on the first one. |
oshima
2017/02/23 02:21:02
I still don't quite Why this stopped working with
afakhry
2017/02/23 18:08:54
Please ignore this file.
| |
534 EnabledDockedWindowsAcceleratorControllerTest() = default; | 532 /* |
oshima
2017/02/23 02:21:02
I prefer #if 0 as it allows nesting.
afakhry
2017/02/23 18:08:54
Please ignore this file.
| |
535 ~EnabledDockedWindowsAcceleratorControllerTest() override = default; | |
536 | |
537 void SetUp() override { | |
538 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
539 ash::switches::kAshEnableDockedWindows); | |
540 AcceleratorControllerTest::SetUp(); | |
541 } | |
542 | |
543 private: | |
544 DISALLOW_COPY_AND_ASSIGN(EnabledDockedWindowsAcceleratorControllerTest); | |
545 }; | |
546 | |
547 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, | |
548 WindowSnapLeftDockLeftRestore) { | |
549 std::unique_ptr<aura::Window> window0( | |
550 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
551 std::unique_ptr<aura::Window> window1( | |
552 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
553 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | |
554 window1_state->Activate(); | |
555 | |
556 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
557 gfx::Rect normal_bounds = window1_state->GetRestoreBoundsInParent(); | |
558 gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( | |
559 WmWindow::Get(window1.get())); | |
560 EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString()); | |
561 EXPECT_TRUE(window1_state->IsSnapped()); | |
562 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
563 EXPECT_FALSE(window1_state->IsNormalOrSnapped()); | |
564 EXPECT_TRUE(window1_state->IsDocked()); | |
565 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
566 EXPECT_FALSE(window1_state->IsDocked()); | |
567 EXPECT_EQ(normal_bounds.ToString(), window1->bounds().ToString()); | |
568 } | |
569 | |
570 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, | |
571 WindowSnapRightDockRightRestore) { | |
572 std::unique_ptr<aura::Window> window0( | |
573 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
574 std::unique_ptr<aura::Window> window1( | |
575 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
576 | |
577 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | |
578 window1_state->Activate(); | |
579 | |
580 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
581 gfx::Rect normal_bounds = window1_state->GetRestoreBoundsInParent(); | |
582 gfx::Rect expected_bounds = wm::GetDefaultRightSnappedWindowBoundsInParent( | |
583 WmWindow::Get(window1.get())); | |
584 EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString()); | |
585 EXPECT_TRUE(window1_state->IsSnapped()); | |
586 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
587 EXPECT_FALSE(window1_state->IsNormalOrSnapped()); | |
588 EXPECT_TRUE(window1_state->IsDocked()); | |
589 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
590 EXPECT_FALSE(window1_state->IsDocked()); | |
591 EXPECT_EQ(normal_bounds.ToString(), window1->bounds().ToString()); | |
592 } | |
593 | |
594 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, | |
595 WindowSnapLeftDockLeftSnapRight) { | |
596 std::unique_ptr<aura::Window> window0( | |
597 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
598 std::unique_ptr<aura::Window> window1( | |
599 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
600 | |
601 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | |
602 window1_state->Activate(); | |
603 | |
604 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
605 gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( | |
606 WmWindow::Get(window1.get())); | |
607 gfx::Rect expected_bounds2 = wm::GetDefaultRightSnappedWindowBoundsInParent( | |
608 WmWindow::Get(window1.get())); | |
609 EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString()); | |
610 EXPECT_TRUE(window1_state->IsSnapped()); | |
611 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
612 EXPECT_FALSE(window1_state->IsNormalOrSnapped()); | |
613 EXPECT_TRUE(window1_state->IsDocked()); | |
614 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
615 EXPECT_FALSE(window1_state->IsDocked()); | |
616 EXPECT_TRUE(window1_state->IsSnapped()); | |
617 EXPECT_EQ(expected_bounds2.ToString(), window1->bounds().ToString()); | |
618 } | |
619 | |
620 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, | |
621 WindowDockLeftMinimizeWindowWithRestore) { | |
622 std::unique_ptr<aura::Window> window0( | |
623 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
624 std::unique_ptr<aura::Window> window1( | |
625 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
626 | |
627 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | |
628 window1_state->Activate(); | |
629 | |
630 std::unique_ptr<aura::Window> window2( | |
631 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
632 | |
633 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); | |
634 | |
635 std::unique_ptr<aura::Window> window3( | |
636 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
637 | |
638 wm::WindowState* window3_state = wm::GetWindowState(window3.get()); | |
639 window3_state->Activate(); | |
640 | |
641 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
642 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
643 gfx::Rect window3_docked_bounds = window3->bounds(); | |
644 | |
645 window2_state->Activate(); | |
646 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
647 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
648 window1_state->Activate(); | |
649 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
650 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
651 | |
652 EXPECT_TRUE(window3_state->IsDocked()); | |
653 EXPECT_TRUE(window2_state->IsDocked()); | |
654 EXPECT_TRUE(window1_state->IsDocked()); | |
655 EXPECT_TRUE(window3_state->IsMinimized()); | |
656 | |
657 window1_state->Activate(); | |
658 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
659 window2_state->Activate(); | |
660 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
661 window3_state->Unminimize(); | |
662 EXPECT_FALSE(window1_state->IsDocked()); | |
663 EXPECT_FALSE(window2_state->IsDocked()); | |
664 EXPECT_TRUE(window3_state->IsDocked()); | |
665 EXPECT_EQ(window3_docked_bounds.ToString(), window3->bounds().ToString()); | |
666 } | |
667 | |
668 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, | |
669 WindowPanelDockLeftDockRightRestore) { | |
670 // TODO: http://crbug.com/632209. | |
671 if (WmShell::Get()->IsRunningInMash()) | |
672 return; | |
673 std::unique_ptr<aura::Window> window0( | |
674 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
675 | |
676 std::unique_ptr<aura::Window> window(CreatePanel()); | |
677 wm::WindowState* window_state = wm::GetWindowState(window.get()); | |
678 window_state->Activate(); | |
679 | |
680 gfx::Rect window_restore_bounds2 = window->bounds(); | |
681 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
682 gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( | |
683 WmWindow::Get(window.get())); | |
684 gfx::Rect window_restore_bounds = window_state->GetRestoreBoundsInScreen(); | |
685 EXPECT_NE(expected_bounds.ToString(), window->bounds().ToString()); | |
686 EXPECT_FALSE(window_state->IsSnapped()); | |
687 EXPECT_FALSE(window_state->IsNormalOrSnapped()); | |
688 EXPECT_TRUE(window_state->IsDocked()); | |
689 window_state->Restore(); | |
690 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
691 EXPECT_TRUE(window_state->IsDocked()); | |
692 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
693 EXPECT_FALSE(window_state->IsDocked()); | |
694 EXPECT_EQ(window_restore_bounds.ToString(), | |
695 window_restore_bounds2.ToString()); | |
696 EXPECT_EQ(window_restore_bounds.ToString(), window->bounds().ToString()); | |
697 } | |
698 | |
699 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, CenterWindowAccelerator) { | |
700 std::unique_ptr<aura::Window> window( | |
701 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
702 wm::WindowState* window_state = wm::GetWindowState(window.get()); | |
703 window_state->Activate(); | |
704 | |
705 // Center the window using accelerator. | |
706 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); | |
707 gfx::Rect work_area = display::Screen::GetScreen() | |
708 ->GetDisplayNearestWindow(window.get()) | |
709 .work_area(); | |
710 gfx::Rect bounds = window->GetBoundsInScreen(); | |
711 EXPECT_NEAR(bounds.x() - work_area.x(), work_area.right() - bounds.right(), | |
712 1); | |
713 EXPECT_NEAR(bounds.y() - work_area.y(), work_area.bottom() - bounds.bottom(), | |
714 1); | |
715 | |
716 // Add the window to docked container and try to center it. | |
717 window->SetBounds(gfx::Rect(0, 0, 20, 20)); | |
718 const wm::WMEvent event(wm::WM_EVENT_DOCK); | |
719 wm::GetWindowState(window.get())->OnWMEvent(&event); | |
720 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | |
721 | |
722 gfx::Rect docked_bounds = window->GetBoundsInScreen(); | |
723 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); | |
724 // It should not get centered and should remain docked. | |
725 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | |
726 EXPECT_EQ(docked_bounds.ToString(), window->GetBoundsInScreen().ToString()); | |
727 } | |
728 | |
729 TEST_F(AcceleratorControllerTest, AutoRepeat) { | 533 TEST_F(AcceleratorControllerTest, AutoRepeat) { |
730 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 534 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
731 accelerator_a.set_type(ui::ET_KEY_PRESSED); | 535 accelerator_a.set_type(ui::ET_KEY_PRESSED); |
732 TestTarget target_a; | 536 TestTarget target_a; |
733 GetController()->Register({accelerator_a}, &target_a); | 537 GetController()->Register(accelerator_a, &target_a); |
734 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN); | 538 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN); |
735 accelerator_b.set_type(ui::ET_KEY_PRESSED); | 539 accelerator_b.set_type(ui::ET_KEY_PRESSED); |
736 TestTarget target_b; | 540 TestTarget target_b; |
737 GetController()->Register({accelerator_b}, &target_b); | 541 GetController()->Register(accelerator_b, &target_b); |
738 | 542 |
739 ui::test::EventGenerator& generator = GetEventGenerator(); | 543 ui::test::EventGenerator& generator = GetEventGenerator(); |
740 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 544 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
741 generator.ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 545 generator.ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
742 | 546 |
743 EXPECT_EQ(1, target_a.accelerator_pressed_count()); | 547 EXPECT_EQ(1, target_a.accelerator_pressed_count()); |
744 EXPECT_EQ(0, target_a.accelerator_repeat_count()); | 548 EXPECT_EQ(0, target_a.accelerator_repeat_count()); |
745 | 549 |
746 // Long press should generate one | 550 // Long press should generate one |
747 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 551 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
(...skipping 14 matching lines...) Expand all Loading... | |
762 generator.ReleaseKey(ui::VKEY_B, ui::EF_CONTROL_DOWN); | 566 generator.ReleaseKey(ui::VKEY_B, ui::EF_CONTROL_DOWN); |
763 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 567 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
764 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN | ui::EF_IS_REPEAT); | 568 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN | ui::EF_IS_REPEAT); |
765 generator.ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 569 generator.ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
766 | 570 |
767 EXPECT_EQ(1, target_b.accelerator_pressed_count()); | 571 EXPECT_EQ(1, target_b.accelerator_pressed_count()); |
768 EXPECT_EQ(0, target_b.accelerator_repeat_count()); | 572 EXPECT_EQ(0, target_b.accelerator_repeat_count()); |
769 EXPECT_EQ(4, target_a.accelerator_pressed_count()); | 573 EXPECT_EQ(4, target_a.accelerator_pressed_count()); |
770 EXPECT_EQ(4, target_a.accelerator_repeat_count()); | 574 EXPECT_EQ(4, target_a.accelerator_repeat_count()); |
771 } | 575 } |
576 */ | |
772 | 577 |
578 // TODO: update once http://crbug.com/630683 is resolved. | |
579 /* | |
773 TEST_F(AcceleratorControllerTest, Previous) { | 580 TEST_F(AcceleratorControllerTest, Previous) { |
774 ui::test::EventGenerator& generator = GetEventGenerator(); | 581 ui::test::EventGenerator& generator = GetEventGenerator(); |
775 generator.PressKey(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); | 582 generator.PressKey(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); |
776 generator.ReleaseKey(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); | 583 generator.ReleaseKey(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); |
777 | 584 |
778 EXPECT_EQ(ui::VKEY_VOLUME_MUTE, GetPreviousAccelerator().key_code()); | 585 EXPECT_EQ(ui::VKEY_VOLUME_MUTE, GetPreviousAccelerator().key_code()); |
779 EXPECT_EQ(ui::EF_NONE, GetPreviousAccelerator().modifiers()); | 586 EXPECT_EQ(ui::EF_NONE, GetPreviousAccelerator().modifiers()); |
780 | 587 |
781 generator.PressKey(ui::VKEY_TAB, ui::EF_CONTROL_DOWN); | 588 generator.PressKey(ui::VKEY_TAB, ui::EF_CONTROL_DOWN); |
782 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_CONTROL_DOWN); | 589 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_CONTROL_DOWN); |
783 | 590 |
784 EXPECT_EQ(ui::VKEY_TAB, GetPreviousAccelerator().key_code()); | 591 EXPECT_EQ(ui::VKEY_TAB, GetPreviousAccelerator().key_code()); |
785 EXPECT_EQ(ui::EF_CONTROL_DOWN, GetPreviousAccelerator().modifiers()); | 592 EXPECT_EQ(ui::EF_CONTROL_DOWN, GetPreviousAccelerator().modifiers()); |
786 } | 593 } |
594 */ | |
787 | 595 |
788 TEST_F(AcceleratorControllerTest, DontRepeatToggleFullscreen) { | 596 TEST_F(AcceleratorControllerTest, DontRepeatToggleFullscreen) { |
789 const AcceleratorData accelerators[] = { | 597 const AcceleratorData accelerators[] = { |
790 {true, ui::VKEY_J, ui::EF_ALT_DOWN, TOGGLE_FULLSCREEN}, | 598 {true, ui::VKEY_J, ui::EF_ALT_DOWN, TOGGLE_FULLSCREEN}, |
791 {true, ui::VKEY_K, ui::EF_ALT_DOWN, TOGGLE_FULLSCREEN}, | 599 {true, ui::VKEY_K, ui::EF_ALT_DOWN, TOGGLE_FULLSCREEN}, |
792 }; | 600 }; |
793 GetController()->RegisterAccelerators(accelerators, arraysize(accelerators)); | 601 GetController()->RegisterAccelerators(accelerators, arraysize(accelerators)); |
794 | 602 |
795 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 603 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
796 params.context = CurrentContext(); | |
797 params.bounds = gfx::Rect(5, 5, 20, 20); | 604 params.bounds = gfx::Rect(5, 5, 20, 20); |
798 views::Widget* widget = new views::Widget; | 605 views::Widget* widget = new views::Widget; |
606 WmWindow::Get(GetPrimaryRootWindow()) | |
607 ->GetRootWindowController() | |
608 ->ConfigureWidgetInitParamsForContainer( | |
609 widget, kShellWindowId_DefaultContainer, ¶ms); | |
799 widget->Init(params); | 610 widget->Init(params); |
611 widget->GetNativeView()->SetProperty(aura::client::kResizeBehaviorKey, | |
612 ui::mojom::kResizeBehaviorCanMaximize); | |
800 widget->Show(); | 613 widget->Show(); |
801 widget->Activate(); | 614 widget->Activate(); |
802 widget->GetNativeView()->SetProperty(aura::client::kResizeBehaviorKey, | |
803 ui::mojom::kResizeBehaviorCanMaximize); | |
804 | 615 |
805 ui::test::EventGenerator& generator = GetEventGenerator(); | 616 wm::WindowState* window_state = |
806 wm::WindowState* window_state = wm::GetWindowState(widget->GetNativeView()); | 617 WmLookup::Get()->GetWindowForWidget(widget)->GetWindowState(); |
807 | 618 |
808 // Toggling not suppressed. | 619 // Toggling not suppressed. |
809 generator.PressKey(ui::VKEY_J, ui::EF_ALT_DOWN); | 620 ProcessAccelerator(ui::VKEY_J, ui::EF_ALT_DOWN); |
810 EXPECT_TRUE(window_state->IsFullscreen()); | 621 EXPECT_TRUE(window_state->IsFullscreen()); |
811 | 622 |
812 // The same accelerator - toggling suppressed. | 623 // The same accelerator - toggling suppressed. |
813 generator.PressKey(ui::VKEY_J, ui::EF_ALT_DOWN | ui::EF_IS_REPEAT); | 624 ProcessAccelerator(ui::VKEY_J, ui::EF_ALT_DOWN | ui::EF_IS_REPEAT); |
814 EXPECT_TRUE(window_state->IsFullscreen()); | 625 EXPECT_TRUE(window_state->IsFullscreen()); |
815 | 626 |
816 // Different accelerator. | 627 // Different accelerator. |
817 generator.PressKey(ui::VKEY_K, ui::EF_ALT_DOWN); | 628 ProcessAccelerator(ui::VKEY_K, ui::EF_ALT_DOWN); |
818 EXPECT_FALSE(window_state->IsFullscreen()); | 629 EXPECT_FALSE(window_state->IsFullscreen()); |
819 } | 630 } |
820 | 631 |
821 // TODO(oshima): Fix this test to use EventGenerator. | |
822 #if defined(USE_X11) | |
823 TEST_F(AcceleratorControllerTest, ProcessOnce) { | |
824 // The IME event filter interferes with the basic key event propagation we | |
825 // attempt to do here, so we disable it. | |
826 DisableIME(); | |
827 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | |
828 TestTarget target; | |
829 GetController()->Register({accelerator_a}, &target); | |
830 | |
831 // The accelerator is processed only once. | |
832 ui::EventProcessor* dispatcher = | |
833 Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); | |
834 | |
835 ui::ScopedXI2Event key_event; | |
836 key_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); | |
837 ui::KeyEvent key_event1(key_event); | |
838 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1); | |
839 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed); | |
840 | |
841 ui::KeyEvent key_event2('A', ui::VKEY_A, ui::EF_NONE); | |
842 details = dispatcher->OnEventFromSource(&key_event2); | |
843 EXPECT_FALSE(key_event2.handled() || details.dispatcher_destroyed); | |
844 | |
845 key_event.InitKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, 0); | |
846 ui::KeyEvent key_event3(key_event); | |
847 details = dispatcher->OnEventFromSource(&key_event3); | |
848 EXPECT_FALSE(key_event3.handled() || details.dispatcher_destroyed); | |
849 EXPECT_EQ(1, target.accelerator_pressed_count()); | |
850 } | |
851 #endif | |
852 | |
853 TEST_F(AcceleratorControllerTest, GlobalAccelerators) { | 632 TEST_F(AcceleratorControllerTest, GlobalAccelerators) { |
854 // TODO: TestScreenshotDelegate is null in mash http://crbug.com/632111. | |
855 if (WmShell::Get()->IsRunningInMash()) | |
856 return; | |
857 | |
858 // CycleBackward | 633 // CycleBackward |
859 EXPECT_TRUE(ProcessInController( | 634 EXPECT_TRUE(ProcessInController( |
860 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); | 635 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); |
861 // CycleForward | 636 // CycleForward |
862 EXPECT_TRUE( | 637 EXPECT_TRUE( |
863 ProcessInController(ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); | 638 ProcessInController(ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); |
864 // CycleLinear | 639 // CycleLinear |
865 EXPECT_TRUE(ProcessInController( | 640 EXPECT_TRUE(ProcessInController( |
866 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_NONE))); | 641 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_NONE))); |
867 | 642 |
868 // The "Take Screenshot", "Take Partial Screenshot", volume, brightness, and | 643 // The "Take Screenshot", "Take Partial Screenshot", volume, brightness, and |
869 // keyboard brightness accelerators are only defined on ChromeOS. | 644 // keyboard brightness accelerators are only defined on ChromeOS. |
645 // TODO: needs ScreenShotDelegate converted: http://crbug.com/612331. | |
646 /* | |
870 { | 647 { |
871 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate(); | 648 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate(); |
872 delegate->set_can_take_screenshot(false); | 649 delegate->set_can_take_screenshot(false); |
873 EXPECT_TRUE(ProcessInController( | 650 EXPECT_TRUE(ProcessInController( |
874 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); | 651 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); |
875 EXPECT_TRUE( | 652 EXPECT_TRUE( |
876 ProcessInController(ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); | 653 ProcessInController(ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); |
877 EXPECT_TRUE(ProcessInController(ui::Accelerator( | 654 EXPECT_TRUE(ProcessInController(ui::Accelerator( |
878 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | 655 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); |
879 | 656 |
880 delegate->set_can_take_screenshot(true); | 657 delegate->set_can_take_screenshot(true); |
881 EXPECT_EQ(0, delegate->handle_take_screenshot_count()); | 658 EXPECT_EQ(0, delegate->handle_take_screenshot_count()); |
882 EXPECT_TRUE(ProcessInController( | 659 EXPECT_TRUE(ProcessInController( |
883 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); | 660 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); |
884 EXPECT_EQ(1, delegate->handle_take_screenshot_count()); | 661 EXPECT_EQ(1, delegate->handle_take_screenshot_count()); |
885 EXPECT_TRUE( | 662 EXPECT_TRUE( |
886 ProcessInController(ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); | 663 ProcessInController(ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); |
887 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); | 664 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); |
888 EXPECT_TRUE(ProcessInController(ui::Accelerator( | 665 EXPECT_TRUE(ProcessInController(ui::Accelerator( |
889 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | 666 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); |
890 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); | 667 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); |
891 } | 668 } |
669 */ | |
892 const ui::Accelerator volume_mute(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); | 670 const ui::Accelerator volume_mute(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); |
893 const ui::Accelerator volume_down(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); | 671 const ui::Accelerator volume_down(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); |
894 const ui::Accelerator volume_up(ui::VKEY_VOLUME_UP, ui::EF_NONE); | 672 const ui::Accelerator volume_up(ui::VKEY_VOLUME_UP, ui::EF_NONE); |
895 { | 673 { |
896 base::UserActionTester user_action_tester; | 674 base::UserActionTester user_action_tester; |
897 ui::AcceleratorHistory* history = GetController()->accelerator_history(); | 675 ui::AcceleratorHistory* history = GetController()->accelerator_history(); |
898 | 676 |
899 EXPECT_EQ(0, user_action_tester.GetActionCount("Accel_VolumeMute_F8")); | 677 EXPECT_EQ(0, user_action_tester.GetActionCount("Accel_VolumeMute_F8")); |
900 EXPECT_TRUE(ProcessInController(volume_mute)); | 678 EXPECT_TRUE(ProcessInController(volume_mute)); |
901 EXPECT_EQ(1, user_action_tester.GetActionCount("Accel_VolumeMute_F8")); | 679 EXPECT_EQ(1, user_action_tester.GetActionCount("Accel_VolumeMute_F8")); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
985 | 763 |
986 // Show task manager | 764 // Show task manager |
987 EXPECT_TRUE( | 765 EXPECT_TRUE( |
988 ProcessInController(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_SHIFT_DOWN))); | 766 ProcessInController(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_SHIFT_DOWN))); |
989 | 767 |
990 // Open file manager | 768 // Open file manager |
991 EXPECT_TRUE(ProcessInController( | 769 EXPECT_TRUE(ProcessInController( |
992 ui::Accelerator(ui::VKEY_M, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); | 770 ui::Accelerator(ui::VKEY_M, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); |
993 | 771 |
994 // Lock screen | 772 // Lock screen |
995 // NOTE: Accelerators that do not work on the lock screen need to be | 773 // TODO(derat): Reenable this once user sessions work in mash. |
996 // tested before the sequence below is invoked because it causes a side | 774 EXPECT_FALSE( |
997 // effect of locking the screen. | |
998 EXPECT_TRUE( | |
999 ProcessInController(ui::Accelerator(ui::VKEY_L, ui::EF_COMMAND_DOWN))); | 775 ProcessInController(ui::Accelerator(ui::VKEY_L, ui::EF_COMMAND_DOWN))); |
1000 } | 776 } |
1001 | 777 |
1002 TEST_F(AcceleratorControllerTest, GlobalAcceleratorsToggleAppList) { | 778 // TODO: fails in mash, http://crbug.com/632180. |
1003 app_list::test::TestAppListPresenter test_app_list_presenter; | 779 TEST_F(AcceleratorControllerTest, DISABLED_GlobalAcceleratorsToggleAppList) { |
1004 WmShell::Get()->app_list()->SetAppListPresenter( | |
1005 test_app_list_presenter.CreateInterfacePtrAndBind()); | |
1006 AccessibilityDelegate* delegate = WmShell::Get()->accessibility_delegate(); | 780 AccessibilityDelegate* delegate = WmShell::Get()->accessibility_delegate(); |
781 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); | |
1007 | 782 |
1008 // The press event should not toggle the AppList, the release should instead. | 783 // The press event should not open the AppList, the release should instead. |
1009 EXPECT_FALSE( | 784 EXPECT_FALSE( |
1010 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); | 785 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); |
1011 RunAllPendingInMessageLoop(); | |
1012 EXPECT_EQ(ui::VKEY_LWIN, GetCurrentAccelerator().key_code()); | 786 EXPECT_EQ(ui::VKEY_LWIN, GetCurrentAccelerator().key_code()); |
1013 EXPECT_EQ(0u, test_app_list_presenter.toggle_count()); | 787 |
788 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); | |
1014 | 789 |
1015 EXPECT_TRUE( | 790 EXPECT_TRUE( |
1016 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE))); | 791 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE))); |
1017 RunAllPendingInMessageLoop(); | 792 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); |
1018 EXPECT_EQ(1u, test_app_list_presenter.toggle_count()); | 793 |
1019 EXPECT_EQ(ui::VKEY_LWIN, GetPreviousAccelerator().key_code()); | 794 EXPECT_EQ(ui::VKEY_LWIN, GetPreviousAccelerator().key_code()); |
1020 | 795 |
1021 // When spoken feedback is on, the AppList should not toggle. | 796 // When spoken feedback is on, the AppList should not toggle. |
1022 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); | 797 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); |
1023 EXPECT_FALSE( | 798 EXPECT_FALSE( |
1024 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); | 799 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); |
1025 EXPECT_FALSE( | 800 EXPECT_FALSE( |
1026 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE))); | 801 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE))); |
1027 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); | 802 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); |
1028 RunAllPendingInMessageLoop(); | 803 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); |
1029 EXPECT_EQ(1u, test_app_list_presenter.toggle_count()); | |
1030 | 804 |
1031 // Turning off spoken feedback should allow the AppList to toggle again. | |
1032 EXPECT_FALSE( | 805 EXPECT_FALSE( |
1033 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); | 806 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); |
1034 EXPECT_TRUE( | 807 EXPECT_TRUE( |
1035 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE))); | 808 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE))); |
1036 RunAllPendingInMessageLoop(); | 809 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); |
1037 EXPECT_EQ(2u, test_app_list_presenter.toggle_count()); | 810 |
811 // When spoken feedback is on, the AppList should not toggle. | |
812 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); | |
813 EXPECT_FALSE( | |
814 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); | |
815 EXPECT_FALSE( | |
816 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE))); | |
817 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); | |
818 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); | |
1038 | 819 |
1039 // The press of VKEY_BROWSER_SEARCH should toggle the AppList | 820 // The press of VKEY_BROWSER_SEARCH should toggle the AppList |
1040 EXPECT_TRUE(ProcessInController( | 821 EXPECT_TRUE(ProcessInController( |
1041 ui::Accelerator(ui::VKEY_BROWSER_SEARCH, ui::EF_NONE))); | 822 ui::Accelerator(ui::VKEY_BROWSER_SEARCH, ui::EF_NONE))); |
1042 RunAllPendingInMessageLoop(); | 823 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); |
1043 EXPECT_EQ(3u, test_app_list_presenter.toggle_count()); | |
1044 EXPECT_FALSE(ProcessInController( | 824 EXPECT_FALSE(ProcessInController( |
1045 ReleaseAccelerator(ui::VKEY_BROWSER_SEARCH, ui::EF_NONE))); | 825 ReleaseAccelerator(ui::VKEY_BROWSER_SEARCH, ui::EF_NONE))); |
1046 RunAllPendingInMessageLoop(); | 826 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); |
1047 EXPECT_EQ(3u, test_app_list_presenter.toggle_count()); | |
1048 } | 827 } |
1049 | 828 |
1050 TEST_F(AcceleratorControllerTest, ImeGlobalAccelerators) { | 829 TEST_F(AcceleratorControllerTest, ImeGlobalAccelerators) { |
1051 // Test IME shortcuts. | 830 // Test IME shortcuts. |
1052 ui::Accelerator control_space_down(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); | 831 ui::Accelerator control_space_down(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); |
1053 control_space_down.set_type(ui::ET_KEY_PRESSED); | 832 control_space_down.set_type(ui::ET_KEY_PRESSED); |
1054 ui::Accelerator control_space_up(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); | 833 ui::Accelerator control_space_up(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); |
1055 control_space_up.set_type(ui::ET_KEY_RELEASED); | 834 control_space_up.set_type(ui::ET_KEY_RELEASED); |
1056 const ui::Accelerator convert(ui::VKEY_CONVERT, ui::EF_NONE); | 835 const ui::Accelerator convert(ui::VKEY_CONVERT, ui::EF_NONE); |
1057 const ui::Accelerator non_convert(ui::VKEY_NONCONVERT, ui::EF_NONE); | 836 const ui::Accelerator non_convert(ui::VKEY_NONCONVERT, ui::EF_NONE); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1097 ui::VKEY_SPACE, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); | 876 ui::VKEY_SPACE, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); |
1098 EXPECT_FALSE(ProcessInController(shift_alt_space_press)); | 877 EXPECT_FALSE(ProcessInController(shift_alt_space_press)); |
1099 } | 878 } |
1100 | 879 |
1101 TEST_F(AcceleratorControllerTest, PreferredReservedAccelerators) { | 880 TEST_F(AcceleratorControllerTest, PreferredReservedAccelerators) { |
1102 // Power key is reserved on chromeos. | 881 // Power key is reserved on chromeos. |
1103 EXPECT_TRUE(GetController()->IsReserved( | 882 EXPECT_TRUE(GetController()->IsReserved( |
1104 ui::Accelerator(ui::VKEY_POWER, ui::EF_NONE))); | 883 ui::Accelerator(ui::VKEY_POWER, ui::EF_NONE))); |
1105 EXPECT_FALSE(GetController()->IsPreferred( | 884 EXPECT_FALSE(GetController()->IsPreferred( |
1106 ui::Accelerator(ui::VKEY_POWER, ui::EF_NONE))); | 885 ui::Accelerator(ui::VKEY_POWER, ui::EF_NONE))); |
1107 | |
1108 // ALT+Tab are not reserved but preferred. | 886 // ALT+Tab are not reserved but preferred. |
1109 EXPECT_FALSE(GetController()->IsReserved( | 887 EXPECT_FALSE(GetController()->IsReserved( |
1110 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); | 888 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); |
1111 EXPECT_FALSE(GetController()->IsReserved( | 889 EXPECT_FALSE(GetController()->IsReserved( |
1112 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); | 890 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); |
1113 EXPECT_TRUE(GetController()->IsPreferred( | 891 EXPECT_TRUE(GetController()->IsPreferred( |
1114 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); | 892 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); |
1115 EXPECT_TRUE(GetController()->IsPreferred( | 893 EXPECT_TRUE(GetController()->IsPreferred( |
1116 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); | 894 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); |
1117 | 895 |
1118 // Others are not reserved nor preferred | 896 // Others are not reserved nor preferred |
1119 EXPECT_FALSE(GetController()->IsReserved( | 897 EXPECT_FALSE(GetController()->IsReserved( |
1120 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); | 898 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); |
1121 EXPECT_FALSE(GetController()->IsPreferred( | 899 EXPECT_FALSE(GetController()->IsPreferred( |
1122 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); | 900 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); |
1123 EXPECT_FALSE( | 901 EXPECT_FALSE( |
1124 GetController()->IsReserved(ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); | 902 GetController()->IsReserved(ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); |
1125 EXPECT_FALSE( | 903 EXPECT_FALSE( |
1126 GetController()->IsPreferred(ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); | 904 GetController()->IsPreferred(ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); |
1127 EXPECT_FALSE( | 905 EXPECT_FALSE( |
1128 GetController()->IsReserved(ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); | 906 GetController()->IsReserved(ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); |
1129 EXPECT_FALSE( | 907 EXPECT_FALSE( |
1130 GetController()->IsPreferred(ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); | 908 GetController()->IsPreferred(ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); |
1131 } | 909 } |
1132 | 910 |
911 /* | |
1133 namespace { | 912 namespace { |
1134 | 913 |
1135 class TestInputMethodManager | |
1136 : public chromeos::input_method::MockInputMethodManager { | |
1137 public: | |
1138 TestInputMethodManager() = default; | |
1139 ~TestInputMethodManager() override = default; | |
1140 | |
1141 // MockInputMethodManager: | |
1142 chromeos::input_method::ImeKeyboard* GetImeKeyboard() override { | |
1143 return &keyboard_; | |
1144 } | |
1145 | |
1146 private: | |
1147 chromeos::input_method::FakeImeKeyboard keyboard_; | |
1148 | |
1149 DISALLOW_COPY_AND_ASSIGN(TestInputMethodManager); | |
1150 }; | |
1151 | |
1152 class ToggleCapsLockTest : public AcceleratorControllerTest { | |
1153 public: | |
1154 ToggleCapsLockTest() = default; | |
1155 ~ToggleCapsLockTest() override = default; | |
1156 | |
1157 void SetUp() override { | |
1158 AcceleratorControllerTest::SetUp(); | |
1159 chromeos::input_method::InputMethodManager::Initialize( | |
1160 new TestInputMethodManager); | |
1161 } | |
1162 | |
1163 void TearDown() override { | |
1164 chromeos::input_method::InputMethodManager::Shutdown(); | |
1165 AcceleratorControllerTest::TearDown(); | |
1166 } | |
1167 | |
1168 private: | |
1169 DISALLOW_COPY_AND_ASSIGN(ToggleCapsLockTest); | |
1170 }; | |
1171 | |
1172 // Tests the four combinations of the TOGGLE_CAPS_LOCK accelerator. | |
1173 TEST_F(ToggleCapsLockTest, ToggleCapsLockAccelerators) { | |
1174 chromeos::input_method::InputMethodManager* input_method_manager = | |
1175 chromeos::input_method::InputMethodManager::Get(); | |
1176 ASSERT_TRUE(input_method_manager); | |
1177 EXPECT_FALSE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled()); | |
1178 | |
1179 // 1. Press Alt, Press Search, Release Search, Release Alt. | |
1180 // Note when you press Alt then press search, the key_code at this point is | |
1181 // VKEY_LWIN (for search) and Alt is the modifier. | |
1182 const ui::Accelerator press_alt_then_search(ui::VKEY_LWIN, ui::EF_ALT_DOWN); | |
1183 EXPECT_FALSE(ProcessInController(press_alt_then_search)); | |
1184 // When you release Search before Alt, the key_code is still VKEY_LWIN and | |
1185 // Alt is still the modifier. | |
1186 const ReleaseAccelerator release_search_before_alt(ui::VKEY_LWIN, | |
1187 ui::EF_ALT_DOWN); | |
1188 EXPECT_TRUE(ProcessInController(release_search_before_alt)); | |
1189 EXPECT_TRUE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled()); | |
1190 input_method_manager->GetImeKeyboard()->SetCapsLockEnabled(false); | |
1191 | |
1192 // 2. Press Search, Press Alt, Release Search, Release Alt. | |
1193 const ui::Accelerator press_search_then_alt(ui::VKEY_MENU, | |
1194 ui::EF_COMMAND_DOWN); | |
1195 EXPECT_FALSE(ProcessInController(press_search_then_alt)); | |
1196 EXPECT_TRUE(ProcessInController(release_search_before_alt)); | |
1197 EXPECT_TRUE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled()); | |
1198 input_method_manager->GetImeKeyboard()->SetCapsLockEnabled(false); | |
1199 | |
1200 // 3. Press Alt, Press Search, Release Alt, Release Search. | |
1201 EXPECT_FALSE(ProcessInController(press_alt_then_search)); | |
1202 const ReleaseAccelerator release_alt_before_search(ui::VKEY_MENU, | |
1203 ui::EF_COMMAND_DOWN); | |
1204 EXPECT_TRUE(ProcessInController(release_alt_before_search)); | |
1205 EXPECT_TRUE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled()); | |
1206 input_method_manager->GetImeKeyboard()->SetCapsLockEnabled(false); | |
1207 | |
1208 // 4. Press Search, Press Alt, Release Alt, Release Search. | |
1209 EXPECT_FALSE(ProcessInController(press_search_then_alt)); | |
1210 EXPECT_TRUE(ProcessInController(release_alt_before_search)); | |
1211 EXPECT_TRUE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled()); | |
1212 } | |
1213 | |
1214 class PreferredReservedAcceleratorsTest : public test::AshTestBase { | 914 class PreferredReservedAcceleratorsTest : public test::AshTestBase { |
1215 public: | 915 public: |
1216 PreferredReservedAcceleratorsTest() {} | 916 PreferredReservedAcceleratorsTest() {} |
1217 ~PreferredReservedAcceleratorsTest() override {} | 917 ~PreferredReservedAcceleratorsTest() override {} |
1218 | 918 |
1219 // test::AshTestBase: | 919 // test::AshTestBase: |
1220 void SetUp() override { | 920 void SetUp() override { |
1221 AshTestBase::SetUp(); | 921 AshTestBase::SetUp(); |
1222 Shell::GetInstance()->lock_state_controller()->set_animator_for_test( | 922 Shell::GetInstance()->lock_state_controller()->set_animator_for_test( |
1223 new test::TestSessionStateAnimator); | 923 new test::TestSessionStateAnimator); |
1224 } | 924 } |
1225 | 925 |
1226 private: | 926 private: |
1227 DISALLOW_COPY_AND_ASSIGN(PreferredReservedAcceleratorsTest); | 927 DISALLOW_COPY_AND_ASSIGN(PreferredReservedAcceleratorsTest); |
1228 }; | 928 }; |
1229 | 929 |
1230 } // namespace | 930 } // namespace |
1231 | 931 |
932 // TODO: needs LockStateController ported: http://crbug.com/632189. | |
1232 TEST_F(PreferredReservedAcceleratorsTest, AcceleratorsWithFullscreen) { | 933 TEST_F(PreferredReservedAcceleratorsTest, AcceleratorsWithFullscreen) { |
1233 // TODO: needs LockStateController ported: http://crbug.com/632189. | 934 WmWindow* w1 = WmWindow::Get(CreateTestWindow(gfx::Rect())); |
1234 if (WmShell::Get()->IsRunningInMash()) | 935 WmWindow* w2 = WmWindow::Get(CreateTestWindow(gfx::Rect())); |
1235 return; | |
1236 | |
1237 aura::Window* w1 = CreateTestWindowInShellWithId(0); | |
1238 aura::Window* w2 = CreateTestWindowInShellWithId(1); | |
1239 wm::ActivateWindow(w1); | 936 wm::ActivateWindow(w1); |
1240 | 937 |
1241 wm::WMEvent fullscreen(wm::WM_EVENT_FULLSCREEN); | 938 wm::WMEvent fullscreen(wm::WM_EVENT_FULLSCREEN); |
1242 wm::WindowState* w1_state = wm::GetWindowState(w1); | 939 wm::WindowState* w1_state = w1->GetWindowState(); |
1243 w1_state->OnWMEvent(&fullscreen); | 940 w1_state->OnWMEvent(&fullscreen); |
1244 ASSERT_TRUE(w1_state->IsFullscreen()); | 941 ASSERT_TRUE(w1_state->IsFullscreen()); |
1245 | 942 |
1246 ui::test::EventGenerator& generator = GetEventGenerator(); | 943 ui::test::EventGenerator& generator = GetEventGenerator(); |
1247 | |
1248 // Power key (reserved) should always be handled. | 944 // Power key (reserved) should always be handled. |
1249 test::LockStateControllerTestApi test_api( | 945 LockStateController::TestApi test_api( |
1250 Shell::GetInstance()->lock_state_controller()); | 946 Shell::GetInstance()->lock_state_controller()); |
1251 EXPECT_FALSE(test_api.is_animating_lock()); | 947 EXPECT_FALSE(test_api.is_animating_lock()); |
1252 generator.PressKey(ui::VKEY_POWER, ui::EF_NONE); | 948 generator.PressKey(ui::VKEY_POWER, ui::EF_NONE); |
1253 EXPECT_TRUE(test_api.is_animating_lock()); | 949 EXPECT_TRUE(test_api.is_animating_lock()); |
1254 | 950 |
1255 auto press_and_release_alt_tab = [&generator]() { | |
1256 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); | |
1257 // Release the alt key to trigger the window activation. | |
1258 generator.ReleaseKey(ui::VKEY_MENU, ui::EF_NONE); | |
1259 }; | |
1260 | |
1261 // A fullscreen window can consume ALT-TAB (preferred). | 951 // A fullscreen window can consume ALT-TAB (preferred). |
1262 ASSERT_EQ(w1, wm::GetActiveWindow()); | 952 ASSERT_EQ(w1, wm::GetActiveWindow()); |
1263 press_and_release_alt_tab(); | 953 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); |
1264 ASSERT_EQ(w1, wm::GetActiveWindow()); | 954 ASSERT_EQ(w1, wm::GetActiveWindow()); |
1265 ASSERT_NE(w2, wm::GetActiveWindow()); | 955 ASSERT_NE(w2, wm::GetActiveWindow()); |
1266 | 956 |
1267 // ALT-TAB is non repeatable. Press A to cancel the | 957 // ALT-TAB is non repeatable. Press A to cancel the |
1268 // repeat record. | 958 // repeat record. |
1269 generator.PressKey(ui::VKEY_A, ui::EF_NONE); | 959 generator.PressKey(ui::VKEY_A, ui::EF_NONE); |
1270 generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); | 960 generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); |
1271 | 961 |
1272 // A normal window shouldn't consume preferred accelerator. | 962 // A normal window shouldn't consume preferred accelerator. |
1273 wm::WMEvent normal(wm::WM_EVENT_NORMAL); | 963 wm::WMEvent normal(wm::WM_EVENT_NORMAL); |
1274 w1_state->OnWMEvent(&normal); | 964 w1_state->OnWMEvent(&normal); |
1275 ASSERT_FALSE(w1_state->IsFullscreen()); | 965 ASSERT_FALSE(w1_state->IsFullscreen()); |
1276 | 966 |
1277 EXPECT_EQ(w1, wm::GetActiveWindow()); | 967 EXPECT_EQ(w1, wm::GetActiveWindow()); |
1278 press_and_release_alt_tab(); | 968 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); |
1279 ASSERT_NE(w1, wm::GetActiveWindow()); | 969 ASSERT_NE(w1, wm::GetActiveWindow()); |
1280 ASSERT_EQ(w2, wm::GetActiveWindow()); | 970 ASSERT_EQ(w2, wm::GetActiveWindow()); |
1281 } | 971 } |
1282 | 972 |
973 // TODO: needs LockStateController ported: http://crbug.com/632189. | |
1283 TEST_F(PreferredReservedAcceleratorsTest, AcceleratorsWithPinned) { | 974 TEST_F(PreferredReservedAcceleratorsTest, AcceleratorsWithPinned) { |
1284 // TODO: needs LockStateController ported: http://crbug.com/632189. | |
1285 if (WmShell::Get()->IsRunningInMash()) | |
1286 return; | |
1287 aura::Window* w1 = CreateTestWindowInShellWithId(0); | 975 aura::Window* w1 = CreateTestWindowInShellWithId(0); |
1288 aura::Window* w2 = CreateTestWindowInShellWithId(1); | 976 aura::Window* w2 = CreateTestWindowInShellWithId(1); |
1289 wm::ActivateWindow(w1); | 977 wm::ActivateWindow(w1); |
1290 | 978 |
1291 { | 979 { |
1292 wm::WMEvent pin_event(wm::WM_EVENT_PIN); | 980 wm::WMEvent pin_event(wm::WM_EVENT_PIN); |
1293 wm::WindowState* w1_state = wm::GetWindowState(w1); | 981 wm::WindowState* w1_state = wm::GetWindowState(w1); |
1294 w1_state->OnWMEvent(&pin_event); | 982 w1_state->OnWMEvent(&pin_event); |
1295 ASSERT_TRUE(w1_state->IsPinned()); | 983 ASSERT_TRUE(w1_state->IsPinned()); |
1296 } | 984 } |
1297 | 985 |
1298 ui::test::EventGenerator& generator = GetEventGenerator(); | 986 ui::test::EventGenerator& generator = GetEventGenerator(); |
1299 | |
1300 // Power key (reserved) should always be handled. | 987 // Power key (reserved) should always be handled. |
1301 test::LockStateControllerTestApi test_api( | 988 LockStateController::TestApi test_api( |
1302 Shell::GetInstance()->lock_state_controller()); | 989 Shell::GetInstance()->lock_state_controller()); |
1303 EXPECT_FALSE(test_api.is_animating_lock()); | 990 EXPECT_FALSE(test_api.is_animating_lock()); |
1304 generator.PressKey(ui::VKEY_POWER, ui::EF_NONE); | 991 generator.PressKey(ui::VKEY_POWER, ui::EF_NONE); |
1305 EXPECT_TRUE(test_api.is_animating_lock()); | 992 EXPECT_TRUE(test_api.is_animating_lock()); |
1306 | 993 |
1307 // A pinned window can consume ALT-TAB (preferred), but no side effect. | 994 // A pinned window can consume ALT-TAB (preferred), but no side effect. |
1308 ASSERT_EQ(w1, wm::GetActiveWindow()); | 995 ASSERT_EQ(w1, wm::GetActiveWindow()); |
1309 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); | 996 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); |
1310 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); | 997 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); |
1311 ASSERT_EQ(w1, wm::GetActiveWindow()); | 998 ASSERT_EQ(w1, wm::GetActiveWindow()); |
1312 ASSERT_NE(w2, wm::GetActiveWindow()); | 999 ASSERT_NE(w2, wm::GetActiveWindow()); |
1313 } | 1000 } |
1001 */ | |
1314 | 1002 |
1315 TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) { | 1003 TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) { |
1316 // TODO: TestScreenshotDelegate is null in mash http://crbug.com/632111. | |
1317 if (WmShell::Get()->IsRunningInMash()) | |
1318 return; | |
1319 | |
1320 std::set<AcceleratorAction> all_actions; | 1004 std::set<AcceleratorAction> all_actions; |
1321 for (size_t i = 0; i < kAcceleratorDataLength; ++i) | 1005 for (size_t i = 0; i < kAcceleratorDataLength; ++i) |
1322 all_actions.insert(kAcceleratorData[i].action); | 1006 all_actions.insert(kAcceleratorData[i].action); |
1323 std::set<AcceleratorAction> all_debug_actions; | 1007 std::set<AcceleratorAction> all_debug_actions; |
1324 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i) | 1008 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i) |
1325 all_debug_actions.insert(kDebugAcceleratorData[i].action); | 1009 all_debug_actions.insert(kDebugAcceleratorData[i].action); |
1326 std::set<AcceleratorAction> all_dev_actions; | 1010 std::set<AcceleratorAction> all_dev_actions; |
1327 for (size_t i = 0; i < kDeveloperAcceleratorDataLength; ++i) | 1011 for (size_t i = 0; i < kDeveloperAcceleratorDataLength; ++i) |
1328 all_dev_actions.insert(kDeveloperAcceleratorData[i].action); | 1012 all_dev_actions.insert(kDeveloperAcceleratorData[i].action); |
1329 | 1013 |
1330 std::set<AcceleratorAction> actionsAllowedAtModalWindow; | 1014 std::set<AcceleratorAction> actionsAllowedAtModalWindow; |
1331 for (size_t k = 0; k < kActionsAllowedAtModalWindowLength; ++k) | 1015 for (size_t k = 0; k < kActionsAllowedAtModalWindowLength; ++k) |
1332 actionsAllowedAtModalWindow.insert(kActionsAllowedAtModalWindow[k]); | 1016 actionsAllowedAtModalWindow.insert(kActionsAllowedAtModalWindow[k]); |
1333 for (const auto& action : actionsAllowedAtModalWindow) { | 1017 for (const auto& action : actionsAllowedAtModalWindow) { |
1334 EXPECT_TRUE(all_actions.find(action) != all_actions.end() || | 1018 EXPECT_TRUE(all_actions.find(action) != all_actions.end() || |
1335 all_debug_actions.find(action) != all_debug_actions.end() || | 1019 all_debug_actions.find(action) != all_debug_actions.end() || |
1336 all_dev_actions.find(action) != all_dev_actions.end()) | 1020 all_dev_actions.find(action) != all_dev_actions.end()) |
1337 << " action from kActionsAllowedAtModalWindow" | 1021 << " action from kActionsAllowedAtModalWindow" |
1338 << " not found in kAcceleratorData, kDebugAcceleratorData or" | 1022 << " not found in kAcceleratorData, kDebugAcceleratorData or" |
1339 << " kDeveloperAcceleratorData action: " << action; | 1023 << " kDeveloperAcceleratorData action: " << action; |
1340 } | 1024 } |
1341 std::unique_ptr<aura::Window> window( | 1025 WmWindow* window = WmWindow::Get(CreateTestWindow(gfx::Rect(5, 5, 20, 20))); |
1342 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 1026 window->Activate(); |
1343 wm::ActivateWindow(window.get()); | |
1344 WmShell::Get()->SimulateModalWindowOpenForTesting(true); | 1027 WmShell::Get()->SimulateModalWindowOpenForTesting(true); |
1345 for (const auto& action : all_actions) { | 1028 for (const auto& action : all_actions) { |
1346 if (actionsAllowedAtModalWindow.find(action) == | 1029 if (actionsAllowedAtModalWindow.find(action) == |
1347 actionsAllowedAtModalWindow.end()) { | 1030 actionsAllowedAtModalWindow.end()) { |
1348 EXPECT_TRUE(GetController()->PerformActionIfEnabled(action)) | 1031 EXPECT_TRUE(GetController()->PerformActionIfEnabled(action)) |
1349 << " for action (disallowed at modal window): " << action; | 1032 << " for action (disallowed at modal window): " << action; |
1350 } | 1033 } |
1351 } | 1034 } |
1352 // Testing of top row (F5-F10) accelerators that should still work | 1035 // Testing of top row (F5-F10) accelerators that should still work |
1353 // when a modal window is open | 1036 // when a modal window is open |
1354 // | 1037 // |
1355 // Screenshot | 1038 // Screenshot |
1356 { | 1039 // TODO: needs ScreenShotDelegate converted: http://crbug.com/612331. |
1357 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate(); | 1040 /* |
1358 delegate->set_can_take_screenshot(false); | 1041 { |
1359 EXPECT_TRUE(ProcessInController( | 1042 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate(); |
1360 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); | 1043 delegate->set_can_take_screenshot(false); |
1361 EXPECT_TRUE( | 1044 EXPECT_TRUE(ProcessInController( |
1362 ProcessInController(ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); | 1045 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); |
1363 EXPECT_TRUE(ProcessInController(ui::Accelerator( | 1046 EXPECT_TRUE( |
1364 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | 1047 ProcessInController(ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); |
1365 delegate->set_can_take_screenshot(true); | 1048 EXPECT_TRUE(ProcessInController(ui::Accelerator( |
1366 EXPECT_EQ(0, delegate->handle_take_screenshot_count()); | 1049 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | |
1367 EXPECT_TRUE(ProcessInController( | 1050 ui::EF_CONTROL_DOWN))); |
1368 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); | 1051 delegate->set_can_take_screenshot(true); |
1369 EXPECT_EQ(1, delegate->handle_take_screenshot_count()); | 1052 EXPECT_EQ(0, delegate->handle_take_screenshot_count()); |
1370 EXPECT_TRUE( | 1053 EXPECT_TRUE(ProcessInController( |
1371 ProcessInController(ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); | 1054 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); |
1372 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); | 1055 EXPECT_EQ(1, delegate->handle_take_screenshot_count()); |
1373 EXPECT_TRUE(ProcessInController(ui::Accelerator( | 1056 EXPECT_TRUE( |
1374 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | 1057 ProcessInController(ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); |
1375 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); | 1058 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); |
1376 } | 1059 EXPECT_TRUE(ProcessInController(ui::Accelerator( |
1060 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | | |
1061 ui::EF_CONTROL_DOWN))); | |
1062 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); | |
1063 } | |
1064 */ | |
1377 // Brightness | 1065 // Brightness |
1378 const ui::Accelerator brightness_down(ui::VKEY_BRIGHTNESS_DOWN, ui::EF_NONE); | 1066 const ui::Accelerator brightness_down(ui::VKEY_BRIGHTNESS_DOWN, ui::EF_NONE); |
1379 const ui::Accelerator brightness_up(ui::VKEY_BRIGHTNESS_UP, ui::EF_NONE); | 1067 const ui::Accelerator brightness_up(ui::VKEY_BRIGHTNESS_UP, ui::EF_NONE); |
1380 { | 1068 { |
1381 DummyBrightnessControlDelegate* delegate = | 1069 DummyBrightnessControlDelegate* delegate = |
1382 new DummyBrightnessControlDelegate; | 1070 new DummyBrightnessControlDelegate; |
1383 SetBrightnessControlDelegate( | 1071 SetBrightnessControlDelegate( |
1384 std::unique_ptr<BrightnessControlDelegate>(delegate)); | 1072 std::unique_ptr<BrightnessControlDelegate>(delegate)); |
1385 EXPECT_EQ(0, delegate->handle_brightness_down_count()); | 1073 EXPECT_EQ(0, delegate->handle_brightness_down_count()); |
1386 EXPECT_TRUE(ProcessInController(brightness_down)); | 1074 EXPECT_TRUE(ProcessInController(brightness_down)); |
(...skipping 22 matching lines...) Expand all Loading... | |
1409 EXPECT_EQ(1, user_action_tester.GetActionCount("Accel_VolumeDown_F9")); | 1097 EXPECT_EQ(1, user_action_tester.GetActionCount("Accel_VolumeDown_F9")); |
1410 EXPECT_EQ(volume_down, history->current_accelerator()); | 1098 EXPECT_EQ(volume_down, history->current_accelerator()); |
1411 | 1099 |
1412 EXPECT_EQ(0, user_action_tester.GetActionCount("Accel_VolumeUp_F10")); | 1100 EXPECT_EQ(0, user_action_tester.GetActionCount("Accel_VolumeUp_F10")); |
1413 EXPECT_TRUE(ProcessInController(volume_up)); | 1101 EXPECT_TRUE(ProcessInController(volume_up)); |
1414 EXPECT_EQ(volume_up, history->current_accelerator()); | 1102 EXPECT_EQ(volume_up, history->current_accelerator()); |
1415 EXPECT_EQ(1, user_action_tester.GetActionCount("Accel_VolumeUp_F10")); | 1103 EXPECT_EQ(1, user_action_tester.GetActionCount("Accel_VolumeUp_F10")); |
1416 } | 1104 } |
1417 } | 1105 } |
1418 | 1106 |
1419 TEST_F(AcceleratorControllerTest, DisallowedWithNoWindow) { | 1107 // TODO: reenable. Disabled because shelf asynchronously created: |
1108 // http://crbug.com/632192. | |
1109 TEST_F(AcceleratorControllerTest, DISABLED_DisallowedWithNoWindow) { | |
1420 AccessibilityDelegate* delegate = WmShell::Get()->accessibility_delegate(); | 1110 AccessibilityDelegate* delegate = WmShell::Get()->accessibility_delegate(); |
1421 | 1111 |
1422 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) { | 1112 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) { |
1423 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE); | 1113 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE); |
1424 EXPECT_TRUE( | 1114 EXPECT_TRUE( |
1425 GetController()->PerformActionIfEnabled(kActionsNeedingWindow[i])); | 1115 GetController()->PerformActionIfEnabled(kActionsNeedingWindow[i])); |
1426 EXPECT_EQ(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_WINDOW_NEEDED); | 1116 EXPECT_EQ(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_WINDOW_NEEDED); |
1427 } | 1117 } |
1428 | 1118 |
1429 // Make sure we don't alert if we do have a window. | 1119 // Make sure we don't alert if we do have a window. |
1430 std::unique_ptr<aura::Window> window; | |
1431 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) { | 1120 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) { |
1432 window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 1121 aura::Window* aura_window = CreateTestWindow(gfx::Rect(5, 5, 20, 20)); |
1433 wm::ActivateWindow(window.get()); | 1122 WmWindow::Get(aura_window)->Activate(); |
1434 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE); | 1123 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE); |
1435 GetController()->PerformActionIfEnabled(kActionsNeedingWindow[i]); | 1124 GetController()->PerformActionIfEnabled(kActionsNeedingWindow[i]); |
1436 EXPECT_NE(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_WINDOW_NEEDED); | 1125 EXPECT_NE(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_WINDOW_NEEDED); |
1126 delete aura_window; | |
1437 } | 1127 } |
1438 | 1128 |
1439 // Don't alert if we have a minimized window either. | 1129 // Don't alert if we have a minimized window either. |
1440 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) { | 1130 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) { |
1441 window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 1131 aura::Window* aura_window = CreateTestWindow(gfx::Rect(5, 5, 20, 20)); |
1442 wm::ActivateWindow(window.get()); | 1132 WmWindow::Get(aura_window)->Activate(); |
1443 GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE); | 1133 GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE); |
1444 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE); | 1134 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE); |
1445 GetController()->PerformActionIfEnabled(kActionsNeedingWindow[i]); | 1135 GetController()->PerformActionIfEnabled(kActionsNeedingWindow[i]); |
1446 EXPECT_NE(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_WINDOW_NEEDED); | 1136 EXPECT_NE(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_WINDOW_NEEDED); |
1137 delete aura_window; | |
1447 } | 1138 } |
1448 } | 1139 } |
1449 | 1140 |
1450 namespace { | 1141 namespace { |
1451 | 1142 |
1452 // defines a class to test the behavior of deprecated accelerators. | 1143 // defines a class to test the behavior of deprecated accelerators. |
1453 class DeprecatedAcceleratorTester : public AcceleratorControllerTest { | 1144 class DeprecatedAcceleratorTester : public AcceleratorControllerTest { |
1454 public: | 1145 public: |
1455 DeprecatedAcceleratorTester() {} | 1146 DeprecatedAcceleratorTester() {} |
1456 ~DeprecatedAcceleratorTester() override {} | 1147 ~DeprecatedAcceleratorTester() override {} |
1457 | 1148 |
1149 // TODO: this override should be removed and put in WmTestBase. | |
1150 // http://crbug.com/632200. | |
1151 void UnblockUserSession() {} | |
1152 | |
1458 void SetUp() override { | 1153 void SetUp() override { |
1459 AcceleratorControllerTest::SetUp(); | 1154 AcceleratorControllerTest::SetUp(); |
1460 | 1155 |
1461 // For testing the deprecated and new IME shortcuts. | 1156 // For testing the deprecated and new IME shortcuts. |
1462 DummyImeControlDelegate* delegate = new DummyImeControlDelegate; | 1157 DummyImeControlDelegate* delegate = new DummyImeControlDelegate; |
1463 GetController()->SetImeControlDelegate( | 1158 GetController()->SetImeControlDelegate( |
1464 std::unique_ptr<ImeControlDelegate>(delegate)); | 1159 std::unique_ptr<ImeControlDelegate>(delegate)); |
1465 } | 1160 } |
1466 | 1161 |
1467 ui::Accelerator CreateAccelerator(const AcceleratorData& data) const { | 1162 ui::Accelerator CreateAccelerator(const AcceleratorData& data) const { |
(...skipping 26 matching lines...) Expand all Loading... | |
1494 message_center::MessageCenter* message_center() const { | 1189 message_center::MessageCenter* message_center() const { |
1495 return message_center::MessageCenter::Get(); | 1190 return message_center::MessageCenter::Get(); |
1496 } | 1191 } |
1497 | 1192 |
1498 private: | 1193 private: |
1499 DISALLOW_COPY_AND_ASSIGN(DeprecatedAcceleratorTester); | 1194 DISALLOW_COPY_AND_ASSIGN(DeprecatedAcceleratorTester); |
1500 }; | 1195 }; |
1501 | 1196 |
1502 } // namespace | 1197 } // namespace |
1503 | 1198 |
1504 TEST_F(DeprecatedAcceleratorTester, TestDeprecatedAcceleratorsBehavior) { | 1199 // TODO: disabled because of UnblockUserSession() not working: |
1505 // TODO: disabled because of UnblockUserSession() not working: | 1200 // http://crbug.com/632201. |
1506 // http://crbug.com/632201. | 1201 TEST_F(DeprecatedAcceleratorTester, |
1507 if (WmShell::Get()->IsRunningInMash()) | 1202 DISABLED_TestDeprecatedAcceleratorsBehavior) { |
1508 return; | |
1509 for (size_t i = 0; i < kDeprecatedAcceleratorsLength; ++i) { | 1203 for (size_t i = 0; i < kDeprecatedAcceleratorsLength; ++i) { |
1510 const AcceleratorData& entry = kDeprecatedAccelerators[i]; | 1204 const AcceleratorData& entry = kDeprecatedAccelerators[i]; |
1511 | 1205 |
1512 auto itr = GetController()->actions_with_deprecations_.find(entry.action); | 1206 auto itr = GetController()->actions_with_deprecations_.find(entry.action); |
1513 ASSERT_TRUE(itr != GetController()->actions_with_deprecations_.end()); | 1207 ASSERT_TRUE(itr != GetController()->actions_with_deprecations_.end()); |
1514 const DeprecatedAcceleratorData* data = itr->second; | 1208 const DeprecatedAcceleratorData* data = itr->second; |
1515 | 1209 |
1516 EXPECT_TRUE(IsMessageCenterEmpty()); | 1210 EXPECT_TRUE(IsMessageCenterEmpty()); |
1517 ui::Accelerator deprecated_accelerator = CreateAccelerator(entry); | 1211 ui::Accelerator deprecated_accelerator = CreateAccelerator(entry); |
1518 if (data->deprecated_enabled) | 1212 if (data->deprecated_enabled) |
1519 EXPECT_TRUE(ProcessInController(deprecated_accelerator)); | 1213 EXPECT_TRUE(ProcessInController(deprecated_accelerator)); |
1520 else | 1214 else |
1521 EXPECT_FALSE(ProcessInController(deprecated_accelerator)); | 1215 EXPECT_FALSE(ProcessInController(deprecated_accelerator)); |
1522 | 1216 |
1523 // We expect to see a notification in the message center. | 1217 // We expect to see a notification in the message center. |
1524 EXPECT_TRUE( | 1218 EXPECT_TRUE( |
1525 ContainsDeprecatedAcceleratorNotification(data->uma_histogram_name)); | 1219 ContainsDeprecatedAcceleratorNotification(data->uma_histogram_name)); |
1526 RemoveAllNotifications(); | 1220 RemoveAllNotifications(); |
1527 | 1221 |
1528 // If the action is LOCK_SCREEN, we must reset the state by unlocking the | 1222 // If the action is LOCK_SCREEN, we must reset the state by unlocking the |
1529 // screen before we proceed testing the rest of accelerators. | 1223 // screen before we proceed testing the rest of accelerators. |
1530 ResetStateIfNeeded(); | 1224 ResetStateIfNeeded(); |
1531 } | 1225 } |
1532 } | 1226 } |
1533 | 1227 |
1534 TEST_F(DeprecatedAcceleratorTester, TestNewAccelerators) { | 1228 // TODO: disabled because of UnblockUserSession() not working: |
1229 // http://crbug.com/632201. | |
1230 TEST_F(DeprecatedAcceleratorTester, DISABLED_TestNewAccelerators) { | |
1535 // Add below the new accelerators that replaced the deprecated ones (if any). | 1231 // Add below the new accelerators that replaced the deprecated ones (if any). |
1536 const AcceleratorData kNewAccelerators[] = { | 1232 const AcceleratorData kNewAccelerators[] = { |
1537 {true, ui::VKEY_L, ui::EF_COMMAND_DOWN, LOCK_SCREEN}, | 1233 {true, ui::VKEY_L, ui::EF_COMMAND_DOWN, LOCK_SCREEN}, |
1538 {true, ui::VKEY_SPACE, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, NEXT_IME}, | 1234 {true, ui::VKEY_SPACE, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, NEXT_IME}, |
1539 {true, ui::VKEY_ESCAPE, ui::EF_COMMAND_DOWN, SHOW_TASK_MANAGER}, | 1235 {true, ui::VKEY_ESCAPE, ui::EF_COMMAND_DOWN, SHOW_TASK_MANAGER}, |
1540 }; | 1236 }; |
1541 | 1237 |
1542 EXPECT_TRUE(IsMessageCenterEmpty()); | 1238 EXPECT_TRUE(IsMessageCenterEmpty()); |
1543 | 1239 |
1544 for (auto data : kNewAccelerators) { | 1240 for (auto data : kNewAccelerators) { |
1545 EXPECT_TRUE(ProcessInController(CreateAccelerator(data))); | 1241 EXPECT_TRUE(ProcessInController(CreateAccelerator(data))); |
1546 | 1242 |
1547 // Expect no notifications from the new accelerators. | 1243 // Expect no notifications from the new accelerators. |
1548 EXPECT_TRUE(IsMessageCenterEmpty()); | 1244 EXPECT_TRUE(IsMessageCenterEmpty()); |
1549 | 1245 |
1550 // If the action is LOCK_SCREEN, we must reset the state by unlocking the | 1246 // If the action is LOCK_SCREEN, we must reset the state by unlocking the |
1551 // screen before we proceed testing the rest of accelerators. | 1247 // screen before we proceed testing the rest of accelerators. |
1552 ResetStateIfNeeded(); | 1248 ResetStateIfNeeded(); |
1553 } | 1249 } |
1554 } | 1250 } |
1555 | 1251 |
1556 } // namespace ash | 1252 } // namespace ash |
OLD | NEW |