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

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: Add unimplemented methods Created 4 years 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/ime_control_delegate.h" 10 #include "ash/common/ime_control_delegate.h"
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 GetController()->Register(accelerator_a, &target2); 359 GetController()->Register(accelerator_a, &target2);
360 360
361 // If multiple targets are registered with the same accelerator, the target 361 // If multiple targets are registered with the same accelerator, the target
362 // registered later processes the accelerator. 362 // registered later processes the accelerator.
363 EXPECT_TRUE(ProcessInController(accelerator_a)); 363 EXPECT_TRUE(ProcessInController(accelerator_a));
364 EXPECT_EQ(0, target1.accelerator_pressed_count()); 364 EXPECT_EQ(0, target1.accelerator_pressed_count());
365 EXPECT_EQ(1, target2.accelerator_pressed_count()); 365 EXPECT_EQ(1, target2.accelerator_pressed_count());
366 } 366 }
367 367
368 TEST_F(AcceleratorControllerTest, Unregister) { 368 TEST_F(AcceleratorControllerTest, Unregister) {
369 std::vector<ui::Accelerator> ui_accelerators;
370 TestTarget target;
371
369 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 372 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
370 TestTarget target; 373 ui_accelerators.push_back(accelerator_a);
371 GetController()->Register(accelerator_a, &target); 374 GetController()->Register(accelerator_a, &target);
375
372 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); 376 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
377 ui_accelerators.push_back(accelerator_b);
373 GetController()->Register(accelerator_b, &target); 378 GetController()->Register(accelerator_b, &target);
374 379
380 GetController()->Registers(ui_accelerators);
381
375 // Unregistering a different accelerator does not affect the other 382 // Unregistering a different accelerator does not affect the other
376 // accelerator. 383 // accelerator.
377 GetController()->Unregister(accelerator_b, &target); 384 GetController()->Unregister(accelerator_b, &target);
378 EXPECT_TRUE(ProcessInController(accelerator_a)); 385 EXPECT_TRUE(ProcessInController(accelerator_a));
379 EXPECT_EQ(1, target.accelerator_pressed_count()); 386 EXPECT_EQ(1, target.accelerator_pressed_count());
380 387
381 // The unregistered accelerator is no longer processed. 388 // The unregistered accelerator is no longer processed.
382 target.reset(); 389 target.reset();
383 GetController()->Unregister(accelerator_a, &target); 390 GetController()->Unregister(accelerator_a, &target);
384 EXPECT_FALSE(ProcessInController(accelerator_a)); 391 EXPECT_FALSE(ProcessInController(accelerator_a));
385 EXPECT_EQ(0, target.accelerator_pressed_count()); 392 EXPECT_EQ(0, target.accelerator_pressed_count());
386 } 393 }
387 394
388 TEST_F(AcceleratorControllerTest, UnregisterAll) { 395 TEST_F(AcceleratorControllerTest, UnregisterAll) {
396 std::vector<ui::Accelerator> ui_accelerators;
397 TestTarget target1;
398
389 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 399 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
390 TestTarget target1; 400 ui_accelerators.push_back(accelerator_a);
391 GetController()->Register(accelerator_a, &target1); 401 GetController()->Register(accelerator_a, &target1);
402
392 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); 403 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
404 ui_accelerators.push_back(accelerator_b);
393 GetController()->Register(accelerator_b, &target1); 405 GetController()->Register(accelerator_b, &target1);
406
394 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE); 407 const ui::Accelerator accelerator_c(ui::VKEY_C, ui::EF_NONE);
408 ui_accelerators.push_back(accelerator_c);
395 TestTarget target2; 409 TestTarget target2;
396 GetController()->Register(accelerator_c, &target2); 410 GetController()->Register(accelerator_c, &target2);
411
412 GetController()->Registers(ui_accelerators);
413
397 GetController()->UnregisterAll(&target1); 414 GetController()->UnregisterAll(&target1);
398 415
399 // All the accelerators registered for |target1| are no longer processed. 416 // All the accelerators registered for |target1| are no longer processed.
400 EXPECT_FALSE(ProcessInController(accelerator_a)); 417 EXPECT_FALSE(ProcessInController(accelerator_a));
401 EXPECT_FALSE(ProcessInController(accelerator_b)); 418 EXPECT_FALSE(ProcessInController(accelerator_b));
402 EXPECT_EQ(0, target1.accelerator_pressed_count()); 419 EXPECT_EQ(0, target1.accelerator_pressed_count());
403 420
404 // UnregisterAll with a different target does not affect the other target. 421 // UnregisterAll with a different target does not affect the other target.
405 EXPECT_TRUE(ProcessInController(accelerator_c)); 422 EXPECT_TRUE(ProcessInController(accelerator_c));
406 EXPECT_EQ(1, target2.accelerator_pressed_count()); 423 EXPECT_EQ(1, target2.accelerator_pressed_count());
(...skipping 10 matching lines...) Expand all
417 434
418 // The non-registered accelerator is not processed. 435 // The non-registered accelerator is not processed.
419 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); 436 const ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE);
420 EXPECT_FALSE(ProcessInController(accelerator_b)); 437 EXPECT_FALSE(ProcessInController(accelerator_b));
421 } 438 }
422 439
423 TEST_F(AcceleratorControllerTest, IsRegistered) { 440 TEST_F(AcceleratorControllerTest, IsRegistered) {
424 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 441 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
425 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN); 442 const ui::Accelerator accelerator_shift_a(ui::VKEY_A, ui::EF_SHIFT_DOWN);
426 TestTarget target; 443 TestTarget target;
444 std::vector<ui::Accelerator> ui_accelerators;
445 ui_accelerators.push_back(accelerator_a);
427 GetController()->Register(accelerator_a, &target); 446 GetController()->Register(accelerator_a, &target);
447 GetController()->Registers(ui_accelerators);
448
428 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a)); 449 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a));
429 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); 450 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a));
430 GetController()->UnregisterAll(&target); 451 GetController()->UnregisterAll(&target);
431 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); 452 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a));
432 } 453 }
433 454
434 TEST_F(AcceleratorControllerTest, WindowSnap) { 455 TEST_F(AcceleratorControllerTest, WindowSnap) {
435 aura::Window* aura_window = CreateTestWindow(gfx::Rect(5, 5, 20, 20)); 456 aura::Window* aura_window = CreateTestWindow(gfx::Rect(5, 5, 20, 20));
436 WmWindow* window = mus::WmWindowMus::Get(aura_window); 457 WmWindow* window = mus::WmWindowMus::Get(aura_window);
437 wm::WindowState* window_state = window->GetWindowState(); 458 wm::WindowState* window_state = window->GetWindowState();
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 EXPECT_TRUE(IsMessageCenterEmpty()); 1425 EXPECT_TRUE(IsMessageCenterEmpty());
1405 1426
1406 // If the action is LOCK_SCREEN, we must reset the state by unlocking the 1427 // If the action is LOCK_SCREEN, we must reset the state by unlocking the
1407 // screen before we proceed testing the rest of accelerators. 1428 // screen before we proceed testing the rest of accelerators.
1408 ResetStateIfNeeded(); 1429 ResetStateIfNeeded();
1409 } 1430 }
1410 } 1431 }
1411 #endif // defined(OS_CHROMEOS) 1432 #endif // defined(OS_CHROMEOS)
1412 1433
1413 } // namespace ash 1434 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698