Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: ash/accelerators/accelerator_controller_unittest.cc

Issue 2586333003: Make mash register initial batch of accelerators in single shot. (Closed)
Patch Set: remove unnecessary std::vector. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 ewh->HandleAccelerator(); 330 ewh->HandleAccelerator();
331 EXPECT_FALSE(is_idle(ewh)); 331 EXPECT_FALSE(is_idle(ewh));
332 EXPECT_TRUE(is_ui_shown(ewh)); 332 EXPECT_TRUE(is_ui_shown(ewh));
333 333
334 // Exit ash and there should be no crash 334 // Exit ash and there should be no crash
335 } 335 }
336 336
337 TEST_F(AcceleratorControllerTest, Register) { 337 TEST_F(AcceleratorControllerTest, Register) {
338 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 338 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
339 TestTarget target; 339 TestTarget target;
340 GetController()->Register(accelerator_a, &target); 340 GetController()->Register({accelerator_a}, &target);
341 341
342 // The registered accelerator is processed. 342 // The registered accelerator is processed.
343 EXPECT_TRUE(ProcessInController(accelerator_a)); 343 EXPECT_TRUE(ProcessInController(accelerator_a));
344 EXPECT_EQ(1, target.accelerator_pressed_count()); 344 EXPECT_EQ(1, target.accelerator_pressed_count());
345 } 345 }
346 346
347 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { 347 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) {
348 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 348 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
349 const std::vector<ui::Accelerator>& accelerators = {accelerator_a};
mfomitchev 2017/01/24 22:56:02 nit: remove
thanhph1 2017/01/25 20:12:37 Done.
350
349 TestTarget target1; 351 TestTarget target1;
350 GetController()->Register(accelerator_a, &target1); 352 GetController()->Register(accelerators, &target1);
351 TestTarget target2; 353 TestTarget target2;
352 GetController()->Register(accelerator_a, &target2); 354 GetController()->Register(accelerators, &target2);
353 355
354 // If multiple targets are registered with the same accelerator, the target 356 // If multiple targets are registered with the same accelerator, the target
355 // registered later processes the accelerator. 357 // registered later processes the accelerator.
356 EXPECT_TRUE(ProcessInController(accelerator_a)); 358 EXPECT_TRUE(ProcessInController(accelerator_a));
357 EXPECT_EQ(0, target1.accelerator_pressed_count()); 359 EXPECT_EQ(0, target1.accelerator_pressed_count());
358 EXPECT_EQ(1, target2.accelerator_pressed_count()); 360 EXPECT_EQ(1, target2.accelerator_pressed_count());
359 } 361 }
360 362
361 TEST_F(AcceleratorControllerTest, Unregister) { 363 TEST_F(AcceleratorControllerTest, Unregister) {
362 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 364 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
365 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
366
363 TestTarget target; 367 TestTarget target;
364 GetController()->Register(accelerator_a, &target); 368 GetController()->Register({accelerator_a, accelerator_b}, &target);
365 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
366 GetController()->Register(accelerator_b, &target);
367 369
368 // Unregistering a different accelerator does not affect the other 370 // Unregistering a different accelerator does not affect the other
369 // accelerator. 371 // accelerator.
370 GetController()->Unregister(accelerator_b, &target); 372 GetController()->Unregister(accelerator_b, &target);
371 EXPECT_TRUE(ProcessInController(accelerator_a)); 373 EXPECT_TRUE(ProcessInController(accelerator_a));
372 EXPECT_EQ(1, target.accelerator_pressed_count()); 374 EXPECT_EQ(1, target.accelerator_pressed_count());
373 375
374 // The unregistered accelerator is no longer processed. 376 // The unregistered accelerator is no longer processed.
375 target.reset(); 377 target.reset();
376 GetController()->Unregister(accelerator_a, &target); 378 GetController()->Unregister(accelerator_a, &target);
377 EXPECT_FALSE(ProcessInController(accelerator_a)); 379 EXPECT_FALSE(ProcessInController(accelerator_a));
378 EXPECT_EQ(0, target.accelerator_pressed_count()); 380 EXPECT_EQ(0, target.accelerator_pressed_count());
379 } 381 }
380 382
381 TEST_F(AcceleratorControllerTest, UnregisterAll) { 383 TEST_F(AcceleratorControllerTest, UnregisterAll) {
382 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 384 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
385 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
386
383 TestTarget target1; 387 TestTarget target1;
384 GetController()->Register(accelerator_a, &target1); 388 GetController()->Register({accelerator_a, accelerator_b}, &target1);
385 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); 389
386 GetController()->Register(accelerator_b, &target1);
387 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); 390 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE);
388 TestTarget target2; 391 TestTarget target2;
389 GetController()->Register(accelerator_c, &target2); 392 GetController()->Register({accelerator_c}, &target2);
390 GetController()->UnregisterAll(&target1); 393 GetController()->UnregisterAll(&target1);
391 394
392 // All the accelerators registered for |target1| are no longer processed. 395 // All the accelerators registered for |target1| are no longer processed.
393 EXPECT_FALSE(ProcessInController(accelerator_a)); 396 EXPECT_FALSE(ProcessInController(accelerator_a));
394 EXPECT_FALSE(ProcessInController(accelerator_b)); 397 EXPECT_FALSE(ProcessInController(accelerator_b));
395 EXPECT_EQ(0, target1.accelerator_pressed_count()); 398 EXPECT_EQ(0, target1.accelerator_pressed_count());
396 399
397 // UnregisterAll with a different target does not affect the other target. 400 // UnregisterAll with a different target does not affect the other target.
398 EXPECT_TRUE(ProcessInController(accelerator_c)); 401 EXPECT_TRUE(ProcessInController(accelerator_c));
399 EXPECT_EQ(1, target2.accelerator_pressed_count()); 402 EXPECT_EQ(1, target2.accelerator_pressed_count());
400 } 403 }
401 404
402 TEST_F(AcceleratorControllerTest, Process) { 405 TEST_F(AcceleratorControllerTest, Process) {
403 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 406 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
404 TestTarget target1; 407 TestTarget target1;
405 GetController()->Register(accelerator_a, &target1); 408 GetController()->Register({accelerator_a}, &target1);
406 409
407 // The registered accelerator is processed. 410 // The registered accelerator is processed.
408 EXPECT_TRUE(ProcessInController(accelerator_a)); 411 EXPECT_TRUE(ProcessInController(accelerator_a));
409 EXPECT_EQ(1, target1.accelerator_pressed_count()); 412 EXPECT_EQ(1, target1.accelerator_pressed_count());
410 413
411 // The non-registered accelerator is not processed. 414 // The non-registered accelerator is not processed.
412 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); 415 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
413 EXPECT_FALSE(ProcessInController(accelerator_b)); 416 EXPECT_FALSE(ProcessInController(accelerator_b));
414 } 417 }
415 418
416 TEST_F(AcceleratorControllerTest, IsRegistered) { 419 TEST_F(AcceleratorControllerTest, IsRegistered) {
417 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 420 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
418 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN); 421 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN);
422
419 TestTarget target; 423 TestTarget target;
420 GetController()->Register(accelerator_a, &target); 424 GetController()->Register({accelerator_a}, &target);
421 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); 425 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a));
422 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); 426 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a));
423 GetController()->UnregisterAll(&target); 427 GetController()->UnregisterAll(&target);
424 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); 428 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a));
425 } 429 }
426 430
427 TEST_F(AcceleratorControllerTest, WindowSnap) { 431 TEST_F(AcceleratorControllerTest, WindowSnap) {
428 std::unique_ptr<aura::Window> window( 432 std::unique_ptr<aura::Window> window(
429 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); 433 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
430 wm::WindowState* window_state = wm::GetWindowState(window.get()); 434 wm::WindowState* window_state = wm::GetWindowState(window.get());
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 gfx::Rect docked_bounds = window->GetBoundsInScreen(); 713 gfx::Rect docked_bounds = window->GetBoundsInScreen();
710 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); 714 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER);
711 // It should not get centered and should remain docked. 715 // It should not get centered and should remain docked.
712 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); 716 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
713 EXPECT_EQ(docked_bounds.ToString(), window->GetBoundsInScreen().ToString()); 717 EXPECT_EQ(docked_bounds.ToString(), window->GetBoundsInScreen().ToString());
714 } 718 }
715 719
716 TEST_F(AcceleratorControllerTest, AutoRepeat) { 720 TEST_F(AcceleratorControllerTest, AutoRepeat) {
717 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN); 721 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN);
718 accelerator_a.set_type(ui::ET_KEY_PRESSED); 722 accelerator_a.set_type(ui::ET_KEY_PRESSED);
723
719 TestTarget target_a; 724 TestTarget target_a;
720 GetController()->Register(accelerator_a, &target_a); 725 GetController()->Register({accelerator_a}, &target_a);
721 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN); 726 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN);
722 accelerator_b.set_type(ui::ET_KEY_PRESSED); 727 accelerator_b.set_type(ui::ET_KEY_PRESSED);
723 TestTarget target_b; 728 TestTarget target_b;
724 GetController()->Register(accelerator_b, &target_b); 729
730 GetController()->Register({accelerator_b}, &target_b);
725 731
726 ui::test::EventGenerator& generator = GetEventGenerator(); 732 ui::test::EventGenerator& generator = GetEventGenerator();
727 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); 733 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN);
728 generator.ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); 734 generator.ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN);
729 735
730 EXPECT_EQ(1, target_a.accelerator_pressed_count()); 736 EXPECT_EQ(1, target_a.accelerator_pressed_count());
731 EXPECT_EQ(0, target_a.accelerator_repeat_count()); 737 EXPECT_EQ(0, target_a.accelerator_repeat_count());
732 738
733 // Long press should generate one 739 // Long press should generate one
734 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); 740 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 } 812 }
807 813
808 // TODO(oshima): Fix this test to use EventGenerator. 814 // TODO(oshima): Fix this test to use EventGenerator.
809 #if defined(USE_X11) 815 #if defined(USE_X11)
810 TEST_F(AcceleratorControllerTest, ProcessOnce) { 816 TEST_F(AcceleratorControllerTest, ProcessOnce) {
811 // The IME event filter interferes with the basic key event propagation we 817 // The IME event filter interferes with the basic key event propagation we
812 // attempt to do here, so we disable it. 818 // attempt to do here, so we disable it.
813 DisableIME(); 819 DisableIME();
814 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 820 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
815 TestTarget target; 821 TestTarget target;
816 GetController()->Register(accelerator_a, &target); 822
823 GetController()->Register({accelerator_a}, &target);
817 824
818 // The accelerator is processed only once. 825 // The accelerator is processed only once.
819 ui::EventProcessor* dispatcher = 826 ui::EventProcessor* dispatcher =
820 Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); 827 Shell::GetPrimaryRootWindow()->GetHost()->event_processor();
821 828
822 ui::ScopedXI2Event key_event; 829 ui::ScopedXI2Event key_event;
823 key_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); 830 key_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0);
824 ui::KeyEvent key_event1(key_event); 831 ui::KeyEvent key_event1(key_event);
825 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1); 832 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1);
826 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed); 833 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed);
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 // Expect no notifications from the new accelerators. 1443 // Expect no notifications from the new accelerators.
1437 EXPECT_TRUE(IsMessageCenterEmpty()); 1444 EXPECT_TRUE(IsMessageCenterEmpty());
1438 1445
1439 // If the action is LOCK_SCREEN, we must reset the state by unlocking the 1446 // If the action is LOCK_SCREEN, we must reset the state by unlocking the
1440 // screen before we proceed testing the rest of accelerators. 1447 // screen before we proceed testing the rest of accelerators.
1441 ResetStateIfNeeded(); 1448 ResetStateIfNeeded();
1442 } 1449 }
1443 } 1450 }
1444 1451
1445 } // namespace ash 1452 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698