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

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: Pass by const & in AcceleratorManager::Register 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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 TestTarget target; 348 TestTarget target;
349 GetController()->Register(accelerator_a, &target); 349 GetController()->Register({accelerator_a}, &target);
350 350
351 // The registered accelerator is processed. 351 // The registered accelerator is processed.
352 EXPECT_TRUE(ProcessInController(accelerator_a)); 352 EXPECT_TRUE(ProcessInController(accelerator_a));
353 EXPECT_EQ(1, target.accelerator_pressed_count()); 353 EXPECT_EQ(1, target.accelerator_pressed_count());
354 } 354 }
355 355
356 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) { 356 TEST_F(AcceleratorControllerTest, RegisterMultipleTarget) {
357 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 357 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
358 TestTarget target1; 358 TestTarget target1;
359 GetController()->Register(accelerator_a, &target1); 359 GetController()->Register({accelerator_a}, &target1);
360
360 TestTarget target2; 361 TestTarget target2;
361 GetController()->Register(accelerator_a, &target2); 362 GetController()->Register({accelerator_a}, &target2);
362 363
363 // If multiple targets are registered with the same accelerator, the target 364 // If multiple targets are registered with the same accelerator, the target
364 // registered later processes the accelerator. 365 // registered later processes the accelerator.
365 EXPECT_TRUE(ProcessInController(accelerator_a)); 366 EXPECT_TRUE(ProcessInController(accelerator_a));
366 EXPECT_EQ(0, target1.accelerator_pressed_count()); 367 EXPECT_EQ(0, target1.accelerator_pressed_count());
367 EXPECT_EQ(1, target2.accelerator_pressed_count()); 368 EXPECT_EQ(1, target2.accelerator_pressed_count());
368 } 369 }
369 370
370 TEST_F(AcceleratorControllerTest, Unregister) { 371 TEST_F(AcceleratorControllerTest, Unregister) {
372 TestTarget target;
371 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 373 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); 374 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
375 GetController()->Register(accelerator_b, &target); 375
376 GetController()->Register({accelerator_a, accelerator_b}, &target);
376 377
377 // Unregistering a different accelerator does not affect the other 378 // Unregistering a different accelerator does not affect the other
378 // accelerator. 379 // accelerator.
379 GetController()->Unregister(accelerator_b, &target); 380 GetController()->Unregister(accelerator_b, &target);
380 EXPECT_TRUE(ProcessInController(accelerator_a)); 381 EXPECT_TRUE(ProcessInController(accelerator_a));
381 EXPECT_EQ(1, target.accelerator_pressed_count()); 382 EXPECT_EQ(1, target.accelerator_pressed_count());
382 383
383 // The unregistered accelerator is no longer processed. 384 // The unregistered accelerator is no longer processed.
384 target.reset(); 385 target.reset();
385 GetController()->Unregister(accelerator_a, &target); 386 GetController()->Unregister(accelerator_a, &target);
386 EXPECT_FALSE(ProcessInController(accelerator_a)); 387 EXPECT_FALSE(ProcessInController(accelerator_a));
387 EXPECT_EQ(0, target.accelerator_pressed_count()); 388 EXPECT_EQ(0, target.accelerator_pressed_count());
388 } 389 }
389 390
390 TEST_F(AcceleratorControllerTest, UnregisterAll) { 391 TEST_F(AcceleratorControllerTest, UnregisterAll) {
392 TestTarget target1;
391 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 393 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); 394 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
395 GetController()->Register(accelerator_b, &target1); 395
396 GetController()->Register({accelerator_a, accelerator_b}, &target1);
397
396 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); 398 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE);
397 TestTarget target2; 399 TestTarget target2;
398 GetController()->Register(accelerator_c, &target2); 400 GetController()->Register({accelerator_c}, &target2);
399 GetController()->UnregisterAll(&target1); 401 GetController()->UnregisterAll(&target1);
400 402
401 // All the accelerators registered for |target1| are no longer processed. 403 // All the accelerators registered for |target1| are no longer processed.
402 EXPECT_FALSE(ProcessInController(accelerator_a)); 404 EXPECT_FALSE(ProcessInController(accelerator_a));
403 EXPECT_FALSE(ProcessInController(accelerator_b)); 405 EXPECT_FALSE(ProcessInController(accelerator_b));
404 EXPECT_EQ(0, target1.accelerator_pressed_count()); 406 EXPECT_EQ(0, target1.accelerator_pressed_count());
405 407
406 // UnregisterAll with a different target does not affect the other target. 408 // UnregisterAll with a different target does not affect the other target.
407 EXPECT_TRUE(ProcessInController(accelerator_c)); 409 EXPECT_TRUE(ProcessInController(accelerator_c));
408 EXPECT_EQ(1, target2.accelerator_pressed_count()); 410 EXPECT_EQ(1, target2.accelerator_pressed_count());
409 } 411 }
410 412
411 TEST_F(AcceleratorControllerTest, Process) { 413 TEST_F(AcceleratorControllerTest, Process) {
412 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 414 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
413 TestTarget target1; 415 TestTarget target1;
414 GetController()->Register(accelerator_a, &target1); 416 GetController()->Register({accelerator_a}, &target1);
415 417
416 // The registered accelerator is processed. 418 // The registered accelerator is processed.
417 EXPECT_TRUE(ProcessInController(accelerator_a)); 419 EXPECT_TRUE(ProcessInController(accelerator_a));
418 EXPECT_EQ(1, target1.accelerator_pressed_count()); 420 EXPECT_EQ(1, target1.accelerator_pressed_count());
419 421
420 // The non-registered accelerator is not processed. 422 // The non-registered accelerator is not processed.
421 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); 423 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
422 EXPECT_FALSE(ProcessInController(accelerator_b)); 424 EXPECT_FALSE(ProcessInController(accelerator_b));
423 } 425 }
424 426
425 TEST_F(AcceleratorControllerTest, IsRegistered) { 427 TEST_F(AcceleratorControllerTest, IsRegistered) {
426 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 428 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); 429 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN);
428 TestTarget target; 430 TestTarget target;
429 GetController()->Register(accelerator_a, &target); 431 GetController()->Register({accelerator_a}, &target);
432
430 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); 433 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a));
431 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); 434 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a));
432 GetController()->UnregisterAll(&target); 435 GetController()->UnregisterAll(&target);
433 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); 436 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a));
434 } 437 }
435 438
436 TEST_F(AcceleratorControllerTest, WindowSnap) { 439 TEST_F(AcceleratorControllerTest, WindowSnap) {
437 aura::Window* aura_window = CreateTestWindow(gfx::Rect(5, 5, 20, 20)); 440 aura::Window* aura_window = CreateTestWindow(gfx::Rect(5, 5, 20, 20));
438 WmWindow* window = WmWindow::Get(aura_window); 441 WmWindow* window = WmWindow::Get(aura_window);
439 wm::WindowState* window_state = window->GetWindowState(); 442 wm::WindowState* window_state = window->GetWindowState();
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after
1458 EXPECT_TRUE(IsMessageCenterEmpty()); 1461 EXPECT_TRUE(IsMessageCenterEmpty());
1459 1462
1460 // If the action is LOCK_SCREEN, we must reset the state by unlocking the 1463 // If the action is LOCK_SCREEN, we must reset the state by unlocking the
1461 // screen before we proceed testing the rest of accelerators. 1464 // screen before we proceed testing the rest of accelerators.
1462 ResetStateIfNeeded(); 1465 ResetStateIfNeeded();
1463 } 1466 }
1464 } 1467 }
1465 #endif // defined(OS_CHROMEOS) 1468 #endif // defined(OS_CHROMEOS)
1466 1469
1467 } // namespace ash 1470 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698