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

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 comments. Move inline function to .h 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
« no previous file with comments | « no previous file | ash/common/accelerators/accelerator_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
386 GetController()->Register(accelerator_b, &target1);
387 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); 393 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE);
388 TestTarget target2; 394 TestTarget target2;
389 GetController()->Register(accelerator_c, &target2); 395 GetController()->Register({accelerator_c}, &target2);
390 GetController()->UnregisterAll(&target1); 396 GetController()->UnregisterAll(&target1);
391 397
392 // All the accelerators registered for |target1| are no longer processed. 398 // All the accelerators registered for |target1| are no longer processed.
393 EXPECT_FALSE(ProcessInController(accelerator_a)); 399 EXPECT_FALSE(ProcessInController(accelerator_a));
394 EXPECT_FALSE(ProcessInController(accelerator_b)); 400 EXPECT_FALSE(ProcessInController(accelerator_b));
395 EXPECT_EQ(0, target1.accelerator_pressed_count()); 401 EXPECT_EQ(0, target1.accelerator_pressed_count());
396 402
397 // UnregisterAll with a different target does not affect the other target. 403 // UnregisterAll with a different target does not affect the other target.
398 EXPECT_TRUE(ProcessInController(accelerator_c)); 404 EXPECT_TRUE(ProcessInController(accelerator_c));
399 EXPECT_EQ(1, target2.accelerator_pressed_count()); 405 EXPECT_EQ(1, target2.accelerator_pressed_count());
400 } 406 }
401 407
402 TEST_F(AcceleratorControllerTest, Process) { 408 TEST_F(AcceleratorControllerTest, Process) {
403 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 409 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
404 TestTarget target1; 410 TestTarget target1;
405 GetController()->Register(accelerator_a, &target1); 411 GetController()->Register({accelerator_a}, &target1);
406 412
407 // The registered accelerator is processed. 413 // The registered accelerator is processed.
408 EXPECT_TRUE(ProcessInController(accelerator_a)); 414 EXPECT_TRUE(ProcessInController(accelerator_a));
409 EXPECT_EQ(1, target1.accelerator_pressed_count()); 415 EXPECT_EQ(1, target1.accelerator_pressed_count());
410 416
411 // The non-registered accelerator is not processed. 417 // The non-registered accelerator is not processed.
412 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); 418 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
413 EXPECT_FALSE(ProcessInController(accelerator_b)); 419 EXPECT_FALSE(ProcessInController(accelerator_b));
414 } 420 }
415 421
416 TEST_F(AcceleratorControllerTest, IsRegistered) { 422 TEST_F(AcceleratorControllerTest, IsRegistered) {
417 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 423 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); 424 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN);
419 TestTarget target; 425 TestTarget target;
420 GetController()->Register(accelerator_a, &target); 426 GetController()->Register({accelerator_a}, &target);
421 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); 427 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a));
422 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); 428 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a));
423 GetController()->UnregisterAll(&target); 429 GetController()->UnregisterAll(&target);
424 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); 430 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a));
425 } 431 }
426 432
427 TEST_F(AcceleratorControllerTest, WindowSnap) { 433 TEST_F(AcceleratorControllerTest, WindowSnap) {
428 std::unique_ptr<aura::Window> window( 434 std::unique_ptr<aura::Window> window(
429 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); 435 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
430 wm::WindowState* window_state = wm::GetWindowState(window.get()); 436 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); 716 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER);
711 // It should not get centered and should remain docked. 717 // It should not get centered and should remain docked.
712 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); 718 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
713 EXPECT_EQ(docked_bounds.ToString(), window->GetBoundsInScreen().ToString()); 719 EXPECT_EQ(docked_bounds.ToString(), window->GetBoundsInScreen().ToString());
714 } 720 }
715 721
716 TEST_F(AcceleratorControllerTest, AutoRepeat) { 722 TEST_F(AcceleratorControllerTest, AutoRepeat) {
717 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN); 723 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN);
718 accelerator_a.set_type(ui::ET_KEY_PRESSED); 724 accelerator_a.set_type(ui::ET_KEY_PRESSED);
719 TestTarget target_a; 725 TestTarget target_a;
720 GetController()->Register(accelerator_a, &target_a); 726 GetController()->Register({accelerator_a}, &target_a);
721 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN); 727 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN);
722 accelerator_b.set_type(ui::ET_KEY_PRESSED); 728 accelerator_b.set_type(ui::ET_KEY_PRESSED);
723 TestTarget target_b; 729 TestTarget target_b;
724 GetController()->Register(accelerator_b, &target_b); 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 GetController()->Register({accelerator_a}, &target);
817 823
818 // The accelerator is processed only once. 824 // The accelerator is processed only once.
819 ui::EventProcessor* dispatcher = 825 ui::EventProcessor* dispatcher =
820 Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); 826 Shell::GetPrimaryRootWindow()->GetHost()->event_processor();
821 827
822 ui::ScopedXI2Event key_event; 828 ui::ScopedXI2Event key_event;
823 key_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); 829 key_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0);
824 ui::KeyEvent key_event1(key_event); 830 ui::KeyEvent key_event1(key_event);
825 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1); 831 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1);
826 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed); 832 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. 1442 // Expect no notifications from the new accelerators.
1437 EXPECT_TRUE(IsMessageCenterEmpty()); 1443 EXPECT_TRUE(IsMessageCenterEmpty());
1438 1444
1439 // If the action is LOCK_SCREEN, we must reset the state by unlocking the 1445 // If the action is LOCK_SCREEN, we must reset the state by unlocking the
1440 // screen before we proceed testing the rest of accelerators. 1446 // screen before we proceed testing the rest of accelerators.
1441 ResetStateIfNeeded(); 1447 ResetStateIfNeeded();
1442 } 1448 }
1443 } 1449 }
1444 1450
1445 } // namespace ash 1451 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/common/accelerators/accelerator_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698