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

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

Issue 2586333003: Make mash register initial batch of accelerators in single shot. (Closed)
Patch Set: Rename Accelerators to AcceleratorList. 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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 ewh->HandleAccelerator(); 338 ewh->HandleAccelerator();
339 EXPECT_FALSE(is_idle(ewh)); 339 EXPECT_FALSE(is_idle(ewh));
340 EXPECT_TRUE(is_ui_shown(ewh)); 340 EXPECT_TRUE(is_ui_shown(ewh));
341 341
342 // Exit ash and there should be no crash 342 // Exit ash and there should be no crash
343 } 343 }
344 #endif // !defined(OS_WIN) 344 #endif // !defined(OS_WIN)
345 345
346 TEST_F(AcceleratorControllerTest, Register) { 346 TEST_F(AcceleratorControllerTest, Register) {
347 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 347 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
348
349 const std::vector<ui::Accelerator>& accelerators = {accelerator_a};
mfomitchev 2017/01/24 21:00:30 no need for the local variable when it's only used
thanhph1 2017/01/24 21:17:06 Done, thanks!
348 TestTarget target; 350 TestTarget target;
349 GetController()->Register(accelerator_a, &target); 351 GetController()->Register(accelerators, &target);
350 352
351 // The registered accelerator is processed. 353 // The registered accelerator is processed.
352 EXPECT_TRUE(ProcessInController(accelerator_a)); 354 EXPECT_TRUE(ProcessInController(accelerator_a));
353 EXPECT_EQ(1, target.accelerator_pressed_count()); 355 EXPECT_EQ(1, target.accelerator_pressed_count());
354 } 356 }
355 357
356 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { 358 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) {
357 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 359 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
360 const std::vector<ui::Accelerator>& accelerators = {accelerator_a};
mfomitchev 2017/01/24 21:00:30 Nit: I wouldn't declare a local var for this eithe
thanhph1 2017/01/24 21:17:06 Done.
361
358 TestTarget target1; 362 TestTarget target1;
359 GetController()->Register(accelerator_a, &target1); 363 GetController()->Register(accelerators, &target1);
364
360 TestTarget target2; 365 TestTarget target2;
361 GetController()->Register(accelerator_a, &target2); 366 GetController()->Register(accelerators, &target2);
362 367
363 // If multiple targets are registered with the same accelerator, the target 368 // If multiple targets are registered with the same accelerator, the target
364 // registered later processes the accelerator. 369 // registered later processes the accelerator.
365 EXPECT_TRUE(ProcessInController(accelerator_a)); 370 EXPECT_TRUE(ProcessInController(accelerator_a));
366 EXPECT_EQ(0, target1.accelerator_pressed_count()); 371 EXPECT_EQ(0, target1.accelerator_pressed_count());
367 EXPECT_EQ(1, target2.accelerator_pressed_count()); 372 EXPECT_EQ(1, target2.accelerator_pressed_count());
368 } 373 }
369 374
370 TEST_F(AcceleratorControllerTest, Unregister) { 375 TEST_F(AcceleratorControllerTest, Unregister) {
376 std::vector<ui::Accelerator> ui_accelerators;
377 TestTarget target;
378
371 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 379 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
372 TestTarget target;
373 GetController()->Register(accelerator_a, &target);
374 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); 380 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
375 GetController()->Register(accelerator_b, &target); 381 const std::vector<ui::Accelerator>& accelerators = {accelerator_a,
382 accelerator_b};
383
384 GetController()->Register(accelerators, &target);
376 385
377 // Unregistering a different accelerator does not affect the other 386 // Unregistering a different accelerator does not affect the other
378 // accelerator. 387 // accelerator.
379 GetController()->Unregister(accelerator_b, &target); 388 GetController()->Unregister(accelerator_b, &target);
380 EXPECT_TRUE(ProcessInController(accelerator_a)); 389 EXPECT_TRUE(ProcessInController(accelerator_a));
381 EXPECT_EQ(1, target.accelerator_pressed_count()); 390 EXPECT_EQ(1, target.accelerator_pressed_count());
382 391
383 // The unregistered accelerator is no longer processed. 392 // The unregistered accelerator is no longer processed.
384 target.reset(); 393 target.reset();
385 GetController()->Unregister(accelerator_a, &target); 394 GetController()->Unregister(accelerator_a, &target);
386 EXPECT_FALSE(ProcessInController(accelerator_a)); 395 EXPECT_FALSE(ProcessInController(accelerator_a));
387 EXPECT_EQ(0, target.accelerator_pressed_count()); 396 EXPECT_EQ(0, target.accelerator_pressed_count());
388 } 397 }
389 398
390 TEST_F(AcceleratorControllerTest, UnregisterAll) { 399 TEST_F(AcceleratorControllerTest, UnregisterAll) {
400 TestTarget target1;
401
391 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 402 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
392 TestTarget target1;
393 GetController()->Register(accelerator_a, &target1);
394 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); 403 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
395 GetController()->Register(accelerator_b, &target1); 404 const std::vector<ui::Accelerator> accelerators = {accelerator_a,
405 accelerator_b};
406
407 GetController()->Register(accelerators, &target1);
408
396 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); 409 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE);
410
411 const std::vector<ui::Accelerator> accelerators_2 = {accelerator_c};
397 TestTarget target2; 412 TestTarget target2;
398 GetController()->Register(accelerator_c, &target2); 413 GetController()->Register(accelerators_2, &target2);
414
399 GetController()->UnregisterAll(&target1); 415 GetController()->UnregisterAll(&target1);
400 416
401 // All the accelerators registered for |target1| are no longer processed. 417 // All the accelerators registered for |target1| are no longer processed.
402 EXPECT_FALSE(ProcessInController(accelerator_a)); 418 EXPECT_FALSE(ProcessInController(accelerator_a));
403 EXPECT_FALSE(ProcessInController(accelerator_b)); 419 EXPECT_FALSE(ProcessInController(accelerator_b));
404 EXPECT_EQ(0, target1.accelerator_pressed_count()); 420 EXPECT_EQ(0, target1.accelerator_pressed_count());
405 421
406 // UnregisterAll with a different target does not affect the other target. 422 // UnregisterAll with a different target does not affect the other target.
407 EXPECT_TRUE(ProcessInController(accelerator_c)); 423 EXPECT_TRUE(ProcessInController(accelerator_c));
408 EXPECT_EQ(1, target2.accelerator_pressed_count()); 424 EXPECT_EQ(1, target2.accelerator_pressed_count());
409 } 425 }
410 426
411 TEST_F(AcceleratorControllerTest, Process) { 427 TEST_F(AcceleratorControllerTest, Process) {
412 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 428 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
429 const std::vector<ui::Accelerator> accelerators = {accelerator_a};
413 TestTarget target1; 430 TestTarget target1;
414 GetController()->Register(accelerator_a, &target1); 431 GetController()->Register(accelerators, &target1);
415 432
416 // The registered accelerator is processed. 433 // The registered accelerator is processed.
417 EXPECT_TRUE(ProcessInController(accelerator_a)); 434 EXPECT_TRUE(ProcessInController(accelerator_a));
418 EXPECT_EQ(1, target1.accelerator_pressed_count()); 435 EXPECT_EQ(1, target1.accelerator_pressed_count());
419 436
420 // The non-registered accelerator is not processed. 437 // The non-registered accelerator is not processed.
421 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); 438 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
422 EXPECT_FALSE(ProcessInController(accelerator_b)); 439 EXPECT_FALSE(ProcessInController(accelerator_b));
423 } 440 }
424 441
425 TEST_F(AcceleratorControllerTest, IsRegistered) { 442 TEST_F(AcceleratorControllerTest, IsRegistered) {
426 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 443 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
427 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN); 444 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN);
428 TestTarget target; 445 TestTarget target;
429 GetController()->Register(accelerator_a, &target); 446 const std::vector<ui::Accelerator> accelerators = {accelerator_a};
447 GetController()->Register(accelerators, &target);
448
430 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); 449 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a));
431 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); 450 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a));
432 GetController()->UnregisterAll(&target); 451 GetController()->UnregisterAll(&target);
433 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); 452 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a));
434 } 453 }
435 454
436 TEST_F(AcceleratorControllerTest, WindowSnap) { 455 TEST_F(AcceleratorControllerTest, WindowSnap) {
437 aura::Window* aura_window = CreateTestWindow(gfx::Rect(5, 5, 20, 20)); 456 aura::Window* aura_window = CreateTestWindow(gfx::Rect(5, 5, 20, 20));
438 WmWindow* window = WmWindow::Get(aura_window); 457 WmWindow* window = WmWindow::Get(aura_window);
439 wm::WindowState* window_state = window->GetWindowState(); 458 wm::WindowState* window_state = window->GetWindowState();
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 EXPECT_TRUE(IsMessageCenterEmpty()); 1479 EXPECT_TRUE(IsMessageCenterEmpty());
1461 1480
1462 // If the action is LOCK_SCREEN, we must reset the state by unlocking the 1481 // If the action is LOCK_SCREEN, we must reset the state by unlocking the
1463 // screen before we proceed testing the rest of accelerators. 1482 // screen before we proceed testing the rest of accelerators.
1464 ResetStateIfNeeded(); 1483 ResetStateIfNeeded();
1465 } 1484 }
1466 } 1485 }
1467 #endif // defined(OS_CHROMEOS) 1486 #endif // defined(OS_CHROMEOS)
1468 1487
1469 } // namespace ash 1488 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698