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

Side by Side Diff: ui/views/controls/button/menu_button_unittest.cc

Issue 1977793006: Pressing spacebar on toolbar buttons triggers the ripple effect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Formatting changes Created 4 years, 7 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 | « ui/views/controls/button/custom_button_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/views/controls/button/menu_button.h" 5 #include "ui/views/controls/button/menu_button.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 EXPECT_EQ(Button::STATE_HOVERED, menu_button_listener.last_source_state()); 430 EXPECT_EQ(Button::STATE_HOVERED, menu_button_listener.last_source_state());
431 } 431 }
432 432
433 TEST_F(MenuButtonTest, InkDropStateForMenuButtonActivationsWithoutListener) { 433 TEST_F(MenuButtonTest, InkDropStateForMenuButtonActivationsWithoutListener) {
434 CreateMenuButtonWithNoListener(); 434 CreateMenuButtonWithNoListener();
435 TestInkDropDelegate ink_drop_delegate; 435 TestInkDropDelegate ink_drop_delegate;
436 ink_drop_delegate.OnAction(InkDropState::ACTION_PENDING); 436 ink_drop_delegate.OnAction(InkDropState::ACTION_PENDING);
437 button()->set_ink_drop_delegate(&ink_drop_delegate); 437 button()->set_ink_drop_delegate(&ink_drop_delegate);
438 button()->Activate(nullptr); 438 button()->Activate(nullptr);
439 439
440 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate.state()); 440 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate.GetTargetInkDropState());
441 } 441 }
442 442
443 TEST_F(MenuButtonTest, 443 TEST_F(MenuButtonTest,
444 InkDropStateForMenuButtonActivationsWithListenerThatDoesntAcquireALock) { 444 InkDropStateForMenuButtonActivationsWithListenerThatDoesntAcquireALock) {
445 TestMenuButtonListener menu_button_listener; 445 TestMenuButtonListener menu_button_listener;
446 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 446 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
447 TestInkDropDelegate ink_drop_delegate; 447 TestInkDropDelegate ink_drop_delegate;
448 button()->set_ink_drop_delegate(&ink_drop_delegate); 448 button()->set_ink_drop_delegate(&ink_drop_delegate);
449 button()->Activate(nullptr); 449 button()->Activate(nullptr);
450 450
451 EXPECT_EQ(InkDropState::ACTION_TRIGGERED, ink_drop_delegate.state()); 451 EXPECT_EQ(InkDropState::ACTION_TRIGGERED,
452 ink_drop_delegate.GetTargetInkDropState());
452 } 453 }
453 454
454 TEST_F( 455 TEST_F(
455 MenuButtonTest, 456 MenuButtonTest,
456 InkDropStateForMenuButtonActivationsWithListenerThatDontReleaseAllLocks) { 457 InkDropStateForMenuButtonActivationsWithListenerThatDontReleaseAllLocks) {
457 PressStateMenuButtonListener menu_button_listener(false); 458 PressStateMenuButtonListener menu_button_listener(false);
458 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 459 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
459 menu_button_listener.set_menu_button(button()); 460 menu_button_listener.set_menu_button(button());
460 TestInkDropDelegate ink_drop_delegate; 461 TestInkDropDelegate ink_drop_delegate;
461 button()->set_ink_drop_delegate(&ink_drop_delegate); 462 button()->set_ink_drop_delegate(&ink_drop_delegate);
462 button()->Activate(nullptr); 463 button()->Activate(nullptr);
463 464
464 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.state()); 465 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.GetTargetInkDropState());
465 466
466 // Prevent the button from accessing invalid memory during clean up. 467 // Prevent the button from accessing invalid memory during clean up.
467 button()->set_ink_drop_delegate(nullptr); 468 button()->set_ink_drop_delegate(nullptr);
468 } 469 }
469 470
470 TEST_F(MenuButtonTest, 471 TEST_F(MenuButtonTest,
471 InkDropStateForMenuButtonActivationsWithListenerThatReleaseAllLocks) { 472 InkDropStateForMenuButtonActivationsWithListenerThatReleaseAllLocks) {
472 PressStateMenuButtonListener menu_button_listener(true); 473 PressStateMenuButtonListener menu_button_listener(true);
473 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 474 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
474 menu_button_listener.set_menu_button(button()); 475 menu_button_listener.set_menu_button(button());
475 TestInkDropDelegate ink_drop_delegate; 476 TestInkDropDelegate ink_drop_delegate;
476 button()->set_ink_drop_delegate(&ink_drop_delegate); 477 button()->set_ink_drop_delegate(&ink_drop_delegate);
477 button()->Activate(nullptr); 478 button()->Activate(nullptr);
478 479
479 EXPECT_EQ(InkDropState::DEACTIVATED, ink_drop_delegate.state()); 480 EXPECT_EQ(InkDropState::DEACTIVATED,
481 ink_drop_delegate.GetTargetInkDropState());
480 } 482 }
481 483
482 TEST_F(MenuButtonTest, InkDropStateForMenuButtonsWithPressedLocks) { 484 TEST_F(MenuButtonTest, InkDropStateForMenuButtonsWithPressedLocks) {
483 CreateMenuButtonWithNoListener(); 485 CreateMenuButtonWithNoListener();
484 TestInkDropDelegate ink_drop_delegate; 486 TestInkDropDelegate ink_drop_delegate;
485 button()->set_ink_drop_delegate(&ink_drop_delegate); 487 button()->set_ink_drop_delegate(&ink_drop_delegate);
486 488
487 std::unique_ptr<MenuButton::PressedLock> pressed_lock1( 489 std::unique_ptr<MenuButton::PressedLock> pressed_lock1(
488 new MenuButton::PressedLock(button())); 490 new MenuButton::PressedLock(button()));
489 491
490 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.state()); 492 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.GetTargetInkDropState());
491 493
492 std::unique_ptr<MenuButton::PressedLock> pressed_lock2( 494 std::unique_ptr<MenuButton::PressedLock> pressed_lock2(
493 new MenuButton::PressedLock(button())); 495 new MenuButton::PressedLock(button()));
494 496
495 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.state()); 497 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.GetTargetInkDropState());
496 498
497 pressed_lock1.reset(); 499 pressed_lock1.reset();
498 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.state()); 500 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.GetTargetInkDropState());
499 501
500 pressed_lock2.reset(); 502 pressed_lock2.reset();
501 EXPECT_EQ(InkDropState::DEACTIVATED, ink_drop_delegate.state()); 503 EXPECT_EQ(InkDropState::DEACTIVATED,
504 ink_drop_delegate.GetTargetInkDropState());
502 } 505 }
503 506
504 // Verifies only one ink drop animation is triggered when multiple PressedLocks 507 // Verifies only one ink drop animation is triggered when multiple PressedLocks
505 // are attached to a MenuButton. 508 // are attached to a MenuButton.
506 TEST_F(MenuButtonTest, OneInkDropAnimationForReentrantPressedLocks) { 509 TEST_F(MenuButtonTest, OneInkDropAnimationForReentrantPressedLocks) {
507 CreateMenuButtonWithNoListener(); 510 CreateMenuButtonWithNoListener();
508 TestInkDropDelegate ink_drop_delegate; 511 TestInkDropDelegate ink_drop_delegate;
509 button()->set_ink_drop_delegate(&ink_drop_delegate); 512 button()->set_ink_drop_delegate(&ink_drop_delegate);
510 513
511 std::unique_ptr<MenuButton::PressedLock> pressed_lock1( 514 std::unique_ptr<MenuButton::PressedLock> pressed_lock1(
512 new MenuButton::PressedLock(button())); 515 new MenuButton::PressedLock(button()));
513 516
514 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.state()); 517 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.GetTargetInkDropState());
515 ink_drop_delegate.OnAction(InkDropState::ACTION_PENDING); 518 ink_drop_delegate.OnAction(InkDropState::ACTION_PENDING);
516 519
517 std::unique_ptr<MenuButton::PressedLock> pressed_lock2( 520 std::unique_ptr<MenuButton::PressedLock> pressed_lock2(
518 new MenuButton::PressedLock(button())); 521 new MenuButton::PressedLock(button()));
519 522
520 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop_delegate.state()); 523 EXPECT_EQ(InkDropState::ACTION_PENDING,
524 ink_drop_delegate.GetTargetInkDropState());
521 } 525 }
522 526
523 // Verifies the InkDropState is left as ACTIVATED if a PressedLock is active 527 // Verifies the InkDropState is left as ACTIVATED if a PressedLock is active
524 // before another Activation occurs. 528 // before another Activation occurs.
525 TEST_F(MenuButtonTest, 529 TEST_F(MenuButtonTest,
526 InkDropStateForMenuButtonWithPressedLockBeforeActivation) { 530 InkDropStateForMenuButtonWithPressedLockBeforeActivation) {
527 TestMenuButtonListener menu_button_listener; 531 TestMenuButtonListener menu_button_listener;
528 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 532 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
529 TestInkDropDelegate ink_drop_delegate; 533 TestInkDropDelegate ink_drop_delegate;
530 button()->set_ink_drop_delegate(&ink_drop_delegate); 534 button()->set_ink_drop_delegate(&ink_drop_delegate);
531 MenuButton::PressedLock lock(button()); 535 MenuButton::PressedLock lock(button());
532 536
533 button()->Activate(nullptr); 537 button()->Activate(nullptr);
534 538
535 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.state()); 539 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.GetTargetInkDropState());
536 } 540 }
537 541
538 #if defined(USE_AURA) 542 #if defined(USE_AURA)
539 543
540 // Tests that the MenuButton does not become pressed if it can be dragged, and a 544 // Tests that the MenuButton does not become pressed if it can be dragged, and a
541 // DragDropClient is processing the events. 545 // DragDropClient is processing the events.
542 TEST_F(MenuButtonTest, DraggableMenuButtonDoesNotActivateOnDrag) { 546 TEST_F(MenuButtonTest, DraggableMenuButtonDoesNotActivateOnDrag) {
543 TestMenuButtonListener menu_button_listener; 547 TestMenuButtonListener menu_button_listener;
544 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 548 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
545 TestDragController drag_controller; 549 TestDragController drag_controller;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 generator()->MoveTouch(gfx::Point(10, 30)); 608 generator()->MoveTouch(gfx::Point(10, 30));
605 generator()->ReleaseTouch(); 609 generator()->ReleaseTouch();
606 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); 610 EXPECT_EQ(Button::STATE_NORMAL, button()->state());
607 EXPECT_EQ(nullptr, menu_button_listener.last_source()); 611 EXPECT_EQ(nullptr, menu_button_listener.last_source());
608 } 612 }
609 613
610 #endif // !defined(OS_MACOSX) || defined(USE_AURA) 614 #endif // !defined(OS_MACOSX) || defined(USE_AURA)
611 615
612 } // namespace views 616 } // namespace views
613 } // namespace test 617 } // namespace test
OLDNEW
« no previous file with comments | « ui/views/controls/button/custom_button_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698