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

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: fix nits/format and refactor AcceleratorControllerTest.Register. Created 3 years, 10 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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 328
329 // Trigger once to show the bubble. 329 // Trigger once to show the bubble.
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 TestTarget target;
338 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 339 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
339 TestTarget target; 340 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
340 GetController()->Register(accelerator_a, &target); 341 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE);
342 const ui::Accelerator accelerator_d(ui::VKEY_D, ui::EF_NONE);
341 343
342 // The registered accelerator is processed. 344 GetController()->Register(
345 {accelerator_a, accelerator_b, accelerator_c, accelerator_d}, &target);
346
347 // The registered accelerators are processed.
343 EXPECT_TRUE(ProcessInController(accelerator_a)); 348 EXPECT_TRUE(ProcessInController(accelerator_a));
344 EXPECT_EQ(1, target.accelerator_pressed_count()); 349 EXPECT_TRUE(ProcessInController(accelerator_b));
350 EXPECT_TRUE(ProcessInController(accelerator_c));
351 EXPECT_TRUE(ProcessInController(accelerator_d));
352 EXPECT_EQ(4, target.accelerator_pressed_count());
345 } 353 }
346 354
347 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { 355 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) {
348 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 356 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
349 TestTarget target1; 357 TestTarget target1;
350 GetController()->Register(accelerator_a, &target1); 358 GetController()->Register({accelerator_a}, &target1);
351 TestTarget target2; 359 TestTarget target2;
352 GetController()->Register(accelerator_a, &target2); 360 GetController()->Register({accelerator_a}, &target2);
353 361
354 // If multiple targets are registered with the same accelerator, the target 362 // If multiple targets are registered with the same accelerator, the target
355 // registered later processes the accelerator. 363 // registered later processes the accelerator.
356 EXPECT_TRUE(ProcessInController(accelerator_a)); 364 EXPECT_TRUE(ProcessInController(accelerator_a));
357 EXPECT_EQ(0, target1.accelerator_pressed_count()); 365 EXPECT_EQ(0, target1.accelerator_pressed_count());
358 EXPECT_EQ(1, target2.accelerator_pressed_count()); 366 EXPECT_EQ(1, target2.accelerator_pressed_count());
359 } 367 }
360 368
361 TEST_F(AcceleratorControllerTest, Unregister) { 369 TEST_F(AcceleratorControllerTest, Unregister) {
362 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 370 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
371 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
363 TestTarget target; 372 TestTarget target;
364 GetController()->Register(accelerator_a, &target); 373 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 374
368 // Unregistering a different accelerator does not affect the other 375 // Unregistering a different accelerator does not affect the other
369 // accelerator. 376 // accelerator.
370 GetController()->Unregister(accelerator_b, &target); 377 GetController()->Unregister(accelerator_b, &target);
371 EXPECT_TRUE(ProcessInController(accelerator_a)); 378 EXPECT_TRUE(ProcessInController(accelerator_a));
372 EXPECT_EQ(1, target.accelerator_pressed_count()); 379 EXPECT_EQ(1, target.accelerator_pressed_count());
373 380
374 // The unregistered accelerator is no longer processed. 381 // The unregistered accelerator is no longer processed.
375 target.reset(); 382 target.reset();
376 GetController()->Unregister(accelerator_a, &target); 383 GetController()->Unregister(accelerator_a, &target);
377 EXPECT_FALSE(ProcessInController(accelerator_a)); 384 EXPECT_FALSE(ProcessInController(accelerator_a));
378 EXPECT_EQ(0, target.accelerator_pressed_count()); 385 EXPECT_EQ(0, target.accelerator_pressed_count());
379 } 386 }
380 387
381 TEST_F(AcceleratorControllerTest, UnregisterAll) { 388 TEST_F(AcceleratorControllerTest, UnregisterAll) {
382 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 389 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
390 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
383 TestTarget target1; 391 TestTarget target1;
384 GetController()->Register(accelerator_a, &target1); 392 GetController()->Register({accelerator_a, accelerator_b}, &target1);
385 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); 393
386 GetController()->Register(accelerator_b, &target1);
387 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); 394 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE);
388 TestTarget target2; 395 TestTarget target2;
389 GetController()->Register(accelerator_c, &target2); 396 GetController()->Register({accelerator_c}, &target2);
390 GetController()->UnregisterAll(&target1); 397 GetController()->UnregisterAll(&target1);
391 398
392 // All the accelerators registered for |target1| are no longer processed. 399 // All the accelerators registered for |target1| are no longer processed.
393 EXPECT_FALSE(ProcessInController(accelerator_a)); 400 EXPECT_FALSE(ProcessInController(accelerator_a));
394 EXPECT_FALSE(ProcessInController(accelerator_b)); 401 EXPECT_FALSE(ProcessInController(accelerator_b));
395 EXPECT_EQ(0, target1.accelerator_pressed_count()); 402 EXPECT_EQ(0, target1.accelerator_pressed_count());
396 403
397 // UnregisterAll with a different target does not affect the other target. 404 // UnregisterAll with a different target does not affect the other target.
398 EXPECT_TRUE(ProcessInController(accelerator_c)); 405 EXPECT_TRUE(ProcessInController(accelerator_c));
399 EXPECT_EQ(1, target2.accelerator_pressed_count()); 406 EXPECT_EQ(1, target2.accelerator_pressed_count());
400 } 407 }
401 408
402 TEST_F(AcceleratorControllerTest, Process) { 409 TEST_F(AcceleratorControllerTest, Process) {
403 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 410 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
404 TestTarget target1; 411 TestTarget target1;
405 GetController()->Register(accelerator_a, &target1); 412 GetController()->Register({accelerator_a}, &target1);
406 413
407 // The registered accelerator is processed. 414 // The registered accelerator is processed.
408 EXPECT_TRUE(ProcessInController(accelerator_a)); 415 EXPECT_TRUE(ProcessInController(accelerator_a));
409 EXPECT_EQ(1, target1.accelerator_pressed_count()); 416 EXPECT_EQ(1, target1.accelerator_pressed_count());
410 417
411 // The non-registered accelerator is not processed. 418 // The non-registered accelerator is not processed.
412 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); 419 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
413 EXPECT_FALSE(ProcessInController(accelerator_b)); 420 EXPECT_FALSE(ProcessInController(accelerator_b));
414 } 421 }
415 422
416 TEST_F(AcceleratorControllerTest, IsRegistered) { 423 TEST_F(AcceleratorControllerTest, IsRegistered) {
417 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 424 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); 425 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN);
419 TestTarget target; 426 TestTarget target;
420 GetController()->Register(accelerator_a, &target); 427 GetController()->Register({accelerator_a}, &target);
421 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); 428 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a));
422 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); 429 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a));
423 GetController()->UnregisterAll(&target); 430 GetController()->UnregisterAll(&target);
424 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); 431 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a));
425 } 432 }
426 433
427 TEST_F(AcceleratorControllerTest, WindowSnap) { 434 TEST_F(AcceleratorControllerTest, WindowSnap) {
428 std::unique_ptr<aura::Window> window( 435 std::unique_ptr<aura::Window> window(
429 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); 436 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
430 wm::WindowState* window_state = wm::GetWindowState(window.get()); 437 wm::WindowState* window_state = wm::GetWindowState(window.get());
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); 717 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER);
711 // It should not get centered and should remain docked. 718 // It should not get centered and should remain docked.
712 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); 719 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
713 EXPECT_EQ(docked_bounds.ToString(), window->GetBoundsInScreen().ToString()); 720 EXPECT_EQ(docked_bounds.ToString(), window->GetBoundsInScreen().ToString());
714 } 721 }
715 722
716 TEST_F(AcceleratorControllerTest, AutoRepeat) { 723 TEST_F(AcceleratorControllerTest, AutoRepeat) {
717 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN); 724 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN);
718 accelerator_a.set_type(ui::ET_KEY_PRESSED); 725 accelerator_a.set_type(ui::ET_KEY_PRESSED);
719 TestTarget target_a; 726 TestTarget target_a;
720 GetController()->Register(accelerator_a, &target_a); 727 GetController()->Register({accelerator_a}, &target_a);
721 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN); 728 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN);
722 accelerator_b.set_type(ui::ET_KEY_PRESSED); 729 accelerator_b.set_type(ui::ET_KEY_PRESSED);
723 TestTarget target_b; 730 TestTarget target_b;
724 GetController()->Register(accelerator_b, &target_b); 731
732 GetController()->Register({accelerator_b}, &target_b);
725 733
726 ui::test::EventGenerator& generator = GetEventGenerator(); 734 ui::test::EventGenerator& generator = GetEventGenerator();
727 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); 735 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN);
728 generator.ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); 736 generator.ReleaseKey(ui::VKEY_A, ui::EF_CONTROL_DOWN);
729 737
730 EXPECT_EQ(1, target_a.accelerator_pressed_count()); 738 EXPECT_EQ(1, target_a.accelerator_pressed_count());
731 EXPECT_EQ(0, target_a.accelerator_repeat_count()); 739 EXPECT_EQ(0, target_a.accelerator_repeat_count());
732 740
733 // Long press should generate one 741 // Long press should generate one
734 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); 742 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 } 814 }
807 815
808 // TODO(oshima): Fix this test to use EventGenerator. 816 // TODO(oshima): Fix this test to use EventGenerator.
809 #if defined(USE_X11) 817 #if defined(USE_X11)
810 TEST_F(AcceleratorControllerTest, ProcessOnce) { 818 TEST_F(AcceleratorControllerTest, ProcessOnce) {
811 // The IME event filter interferes with the basic key event propagation we 819 // The IME event filter interferes with the basic key event propagation we
812 // attempt to do here, so we disable it. 820 // attempt to do here, so we disable it.
813 DisableIME(); 821 DisableIME();
814 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 822 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
815 TestTarget target; 823 TestTarget target;
816 GetController()->Register(accelerator_a, &target); 824
825 GetController()->Register({accelerator_a}, &target);
817 826
818 // The accelerator is processed only once. 827 // The accelerator is processed only once.
819 ui::EventProcessor* dispatcher = 828 ui::EventProcessor* dispatcher =
820 Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); 829 Shell::GetPrimaryRootWindow()->GetHost()->event_processor();
821 830
822 ui::ScopedXI2Event key_event; 831 ui::ScopedXI2Event key_event;
823 key_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); 832 key_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0);
824 ui::KeyEvent key_event1(key_event); 833 ui::KeyEvent key_event1(key_event);
825 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1); 834 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1);
826 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed); 835 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. 1445 // Expect no notifications from the new accelerators.
1437 EXPECT_TRUE(IsMessageCenterEmpty()); 1446 EXPECT_TRUE(IsMessageCenterEmpty());
1438 1447
1439 // If the action is LOCK_SCREEN, we must reset the state by unlocking the 1448 // If the action is LOCK_SCREEN, we must reset the state by unlocking the
1440 // screen before we proceed testing the rest of accelerators. 1449 // screen before we proceed testing the rest of accelerators.
1441 ResetStateIfNeeded(); 1450 ResetStateIfNeeded();
1442 } 1451 }
1443 } 1452 }
1444 1453
1445 } // namespace ash 1454 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698