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

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

Issue 2001843002: Use ink drop hover for focus states on toolbar buttons and location (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: layout Created 4 years, 6 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/md_text_button.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 22 matching lines...) Expand all
33 class TestMenuButton : public MenuButton { 33 class TestMenuButton : public MenuButton {
34 public: 34 public:
35 explicit TestMenuButton(MenuButtonListener* menu_button_listener) 35 explicit TestMenuButton(MenuButtonListener* menu_button_listener)
36 : MenuButton(base::string16(ASCIIToUTF16("button")), 36 : MenuButton(base::string16(ASCIIToUTF16("button")),
37 menu_button_listener, 37 menu_button_listener,
38 false) {} 38 false) {}
39 39
40 ~TestMenuButton() override {} 40 ~TestMenuButton() override {}
41 41
42 // Accessors to protected MenuButton methods. 42 // Accessors to protected MenuButton methods.
43 void set_ink_drop_delegate(InkDropDelegate* ink_drop_delegate) { 43 void set_ink_drop_delegate(
44 MenuButton::set_ink_drop_delegate(ink_drop_delegate); 44 std::unique_ptr<InkDropDelegate> ink_drop_delegate) {
45 InkDropHostView::set_ink_drop_delegate(std::move(ink_drop_delegate));
45 } 46 }
46 47
47 private: 48 private:
48 DISALLOW_COPY_AND_ASSIGN(TestMenuButton); 49 DISALLOW_COPY_AND_ASSIGN(TestMenuButton);
49 }; 50 };
50 51
51 class MenuButtonTest : public ViewsTestBase { 52 class MenuButtonTest : public ViewsTestBase {
52 public: 53 public:
53 MenuButtonTest() : widget_(nullptr), button_(nullptr) {} 54 MenuButtonTest() : widget_(nullptr), button_(nullptr) {}
54 ~MenuButtonTest() override {} 55 ~MenuButtonTest() override {}
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 generator()->PressLeftButton(); 426 generator()->PressLeftButton();
426 EXPECT_EQ(nullptr, menu_button_listener.last_source()); 427 EXPECT_EQ(nullptr, menu_button_listener.last_source());
427 428
428 generator()->ReleaseLeftButton(); 429 generator()->ReleaseLeftButton();
429 EXPECT_EQ(button(), menu_button_listener.last_source()); 430 EXPECT_EQ(button(), menu_button_listener.last_source());
430 EXPECT_EQ(Button::STATE_HOVERED, menu_button_listener.last_source_state()); 431 EXPECT_EQ(Button::STATE_HOVERED, menu_button_listener.last_source_state());
431 } 432 }
432 433
433 TEST_F(MenuButtonTest, InkDropStateForMenuButtonActivationsWithoutListener) { 434 TEST_F(MenuButtonTest, InkDropStateForMenuButtonActivationsWithoutListener) {
434 CreateMenuButtonWithNoListener(); 435 CreateMenuButtonWithNoListener();
435 TestInkDropDelegate ink_drop_delegate; 436 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate();
436 ink_drop_delegate.OnAction(InkDropState::ACTION_PENDING); 437 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING);
437 button()->set_ink_drop_delegate(&ink_drop_delegate); 438 button()->set_ink_drop_delegate(base::WrapUnique(ink_drop_delegate));
438 button()->Activate(nullptr); 439 button()->Activate(nullptr);
439 440
440 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate.GetTargetInkDropState()); 441 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate->GetTargetInkDropState());
441 } 442 }
442 443
443 TEST_F(MenuButtonTest, 444 TEST_F(MenuButtonTest,
444 InkDropStateForMenuButtonActivationsWithListenerThatDoesntAcquireALock) { 445 InkDropStateForMenuButtonActivationsWithListenerThatDoesntAcquireALock) {
445 TestMenuButtonListener menu_button_listener; 446 TestMenuButtonListener menu_button_listener;
446 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 447 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
447 TestInkDropDelegate ink_drop_delegate; 448 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate();
448 button()->set_ink_drop_delegate(&ink_drop_delegate); 449 button()->set_ink_drop_delegate(base::WrapUnique(ink_drop_delegate));
449 button()->Activate(nullptr); 450 button()->Activate(nullptr);
450 451
451 EXPECT_EQ(InkDropState::ACTION_TRIGGERED, 452 EXPECT_EQ(InkDropState::ACTION_TRIGGERED,
452 ink_drop_delegate.GetTargetInkDropState()); 453 ink_drop_delegate->GetTargetInkDropState());
453 } 454 }
454 455
455 TEST_F( 456 TEST_F(
456 MenuButtonTest, 457 MenuButtonTest,
457 InkDropStateForMenuButtonActivationsWithListenerThatDontReleaseAllLocks) { 458 InkDropStateForMenuButtonActivationsWithListenerThatDontReleaseAllLocks) {
458 PressStateMenuButtonListener menu_button_listener(false); 459 PressStateMenuButtonListener menu_button_listener(false);
459 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 460 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
460 menu_button_listener.set_menu_button(button()); 461 menu_button_listener.set_menu_button(button());
461 TestInkDropDelegate ink_drop_delegate; 462 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate();
462 button()->set_ink_drop_delegate(&ink_drop_delegate); 463 button()->set_ink_drop_delegate(base::WrapUnique(ink_drop_delegate));
463 button()->Activate(nullptr); 464 button()->Activate(nullptr);
464 465
465 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.GetTargetInkDropState()); 466 EXPECT_EQ(InkDropState::ACTIVATED,
466 467 ink_drop_delegate->GetTargetInkDropState());
467 // Prevent the button from accessing invalid memory during clean up.
468 button()->set_ink_drop_delegate(nullptr);
469 } 468 }
470 469
471 TEST_F(MenuButtonTest, 470 TEST_F(MenuButtonTest,
472 InkDropStateForMenuButtonActivationsWithListenerThatReleaseAllLocks) { 471 InkDropStateForMenuButtonActivationsWithListenerThatReleaseAllLocks) {
473 PressStateMenuButtonListener menu_button_listener(true); 472 PressStateMenuButtonListener menu_button_listener(true);
474 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 473 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
475 menu_button_listener.set_menu_button(button()); 474 menu_button_listener.set_menu_button(button());
476 TestInkDropDelegate ink_drop_delegate; 475 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate();
477 button()->set_ink_drop_delegate(&ink_drop_delegate); 476 button()->set_ink_drop_delegate(base::WrapUnique(ink_drop_delegate));
478 button()->Activate(nullptr); 477 button()->Activate(nullptr);
479 478
480 EXPECT_EQ(InkDropState::DEACTIVATED, 479 EXPECT_EQ(InkDropState::DEACTIVATED,
481 ink_drop_delegate.GetTargetInkDropState()); 480 ink_drop_delegate->GetTargetInkDropState());
482 } 481 }
483 482
484 TEST_F(MenuButtonTest, InkDropStateForMenuButtonsWithPressedLocks) { 483 TEST_F(MenuButtonTest, InkDropStateForMenuButtonsWithPressedLocks) {
485 CreateMenuButtonWithNoListener(); 484 CreateMenuButtonWithNoListener();
486 TestInkDropDelegate ink_drop_delegate; 485 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate();
487 button()->set_ink_drop_delegate(&ink_drop_delegate); 486 button()->set_ink_drop_delegate(base::WrapUnique(ink_drop_delegate));
488 487
489 std::unique_ptr<MenuButton::PressedLock> pressed_lock1( 488 std::unique_ptr<MenuButton::PressedLock> pressed_lock1(
490 new MenuButton::PressedLock(button())); 489 new MenuButton::PressedLock(button()));
491 490
492 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.GetTargetInkDropState()); 491 EXPECT_EQ(InkDropState::ACTIVATED,
492 ink_drop_delegate->GetTargetInkDropState());
493 493
494 std::unique_ptr<MenuButton::PressedLock> pressed_lock2( 494 std::unique_ptr<MenuButton::PressedLock> pressed_lock2(
495 new MenuButton::PressedLock(button())); 495 new MenuButton::PressedLock(button()));
496 496
497 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.GetTargetInkDropState()); 497 EXPECT_EQ(InkDropState::ACTIVATED,
498 ink_drop_delegate->GetTargetInkDropState());
498 499
499 pressed_lock1.reset(); 500 pressed_lock1.reset();
500 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.GetTargetInkDropState()); 501 EXPECT_EQ(InkDropState::ACTIVATED,
502 ink_drop_delegate->GetTargetInkDropState());
501 503
502 pressed_lock2.reset(); 504 pressed_lock2.reset();
503 EXPECT_EQ(InkDropState::DEACTIVATED, 505 EXPECT_EQ(InkDropState::DEACTIVATED,
504 ink_drop_delegate.GetTargetInkDropState()); 506 ink_drop_delegate->GetTargetInkDropState());
505 } 507 }
506 508
507 // Verifies only one ink drop animation is triggered when multiple PressedLocks 509 // Verifies only one ink drop animation is triggered when multiple PressedLocks
508 // are attached to a MenuButton. 510 // are attached to a MenuButton.
509 TEST_F(MenuButtonTest, OneInkDropAnimationForReentrantPressedLocks) { 511 TEST_F(MenuButtonTest, OneInkDropAnimationForReentrantPressedLocks) {
510 CreateMenuButtonWithNoListener(); 512 CreateMenuButtonWithNoListener();
511 TestInkDropDelegate ink_drop_delegate; 513 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate();
512 button()->set_ink_drop_delegate(&ink_drop_delegate); 514 button()->set_ink_drop_delegate(base::WrapUnique(ink_drop_delegate));
513 515
514 std::unique_ptr<MenuButton::PressedLock> pressed_lock1( 516 std::unique_ptr<MenuButton::PressedLock> pressed_lock1(
515 new MenuButton::PressedLock(button())); 517 new MenuButton::PressedLock(button()));
516 518
517 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.GetTargetInkDropState()); 519 EXPECT_EQ(InkDropState::ACTIVATED,
518 ink_drop_delegate.OnAction(InkDropState::ACTION_PENDING); 520 ink_drop_delegate->GetTargetInkDropState());
521 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING);
519 522
520 std::unique_ptr<MenuButton::PressedLock> pressed_lock2( 523 std::unique_ptr<MenuButton::PressedLock> pressed_lock2(
521 new MenuButton::PressedLock(button())); 524 new MenuButton::PressedLock(button()));
522 525
523 EXPECT_EQ(InkDropState::ACTION_PENDING, 526 EXPECT_EQ(InkDropState::ACTION_PENDING,
524 ink_drop_delegate.GetTargetInkDropState()); 527 ink_drop_delegate->GetTargetInkDropState());
525 } 528 }
526 529
527 // Verifies the InkDropState is left as ACTIVATED if a PressedLock is active 530 // Verifies the InkDropState is left as ACTIVATED if a PressedLock is active
528 // before another Activation occurs. 531 // before another Activation occurs.
529 TEST_F(MenuButtonTest, 532 TEST_F(MenuButtonTest,
530 InkDropStateForMenuButtonWithPressedLockBeforeActivation) { 533 InkDropStateForMenuButtonWithPressedLockBeforeActivation) {
531 TestMenuButtonListener menu_button_listener; 534 TestMenuButtonListener menu_button_listener;
532 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 535 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
533 TestInkDropDelegate ink_drop_delegate; 536 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate();
534 button()->set_ink_drop_delegate(&ink_drop_delegate); 537 button()->set_ink_drop_delegate(base::WrapUnique(ink_drop_delegate));
535 MenuButton::PressedLock lock(button()); 538 MenuButton::PressedLock lock(button());
536 539
537 button()->Activate(nullptr); 540 button()->Activate(nullptr);
538 541
539 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.GetTargetInkDropState()); 542 EXPECT_EQ(InkDropState::ACTIVATED,
543 ink_drop_delegate->GetTargetInkDropState());
540 } 544 }
541 545
542 #if defined(USE_AURA) 546 #if defined(USE_AURA)
543 547
544 // Tests that the MenuButton does not become pressed if it can be dragged, and a 548 // Tests that the MenuButton does not become pressed if it can be dragged, and a
545 // DragDropClient is processing the events. 549 // DragDropClient is processing the events.
546 TEST_F(MenuButtonTest, DraggableMenuButtonDoesNotActivateOnDrag) { 550 TEST_F(MenuButtonTest, DraggableMenuButtonDoesNotActivateOnDrag) {
547 TestMenuButtonListener menu_button_listener; 551 TestMenuButtonListener menu_button_listener;
548 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 552 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
549 TestDragController drag_controller; 553 TestDragController drag_controller;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 generator()->MoveTouch(gfx::Point(10, 30)); 612 generator()->MoveTouch(gfx::Point(10, 30));
609 generator()->ReleaseTouch(); 613 generator()->ReleaseTouch();
610 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); 614 EXPECT_EQ(Button::STATE_NORMAL, button()->state());
611 EXPECT_EQ(nullptr, menu_button_listener.last_source()); 615 EXPECT_EQ(nullptr, menu_button_listener.last_source());
612 } 616 }
613 617
614 #endif // !defined(OS_MACOSX) || defined(USE_AURA) 618 #endif // !defined(OS_MACOSX) || defined(USE_AURA)
615 619
616 } // namespace views 620 } // namespace views
617 } // namespace test 621 } // namespace test
OLDNEW
« no previous file with comments | « ui/views/controls/button/md_text_button.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698