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

Side by Side Diff: ui/views/controls/button/custom_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
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 "ui/views/controls/button/custom_button.h" 5 #include "ui/views/controls/button/custom_button.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 80
81 private: 81 private:
82 bool pressed_ = false; 82 bool pressed_ = false;
83 bool canceled_ = false; 83 bool canceled_ = false;
84 84
85 DISALLOW_COPY_AND_ASSIGN(TestCustomButton); 85 DISALLOW_COPY_AND_ASSIGN(TestCustomButton);
86 }; 86 };
87 87
88 // An InkDropDelegate that keeps track of ink drop visibility. 88 // An InkDropDelegate that keeps track of ink drop visibility.
89 class TestInkDropDelegateThatTracksVisibilty : public InkDropDelegate { 89 class TestInkDropDelegateThatTracksVisibilty : public TestInkDropDelegate {
90 public: 90 public:
91 TestInkDropDelegateThatTracksVisibilty(bool* ink_shown, bool* ink_hidden) 91 TestInkDropDelegateThatTracksVisibilty(bool* ink_shown, bool* ink_hidden)
92 : ink_shown_(ink_shown), ink_hidden_(ink_hidden) {} 92 : ink_shown_(ink_shown), ink_hidden_(ink_hidden) {}
93 ~TestInkDropDelegateThatTracksVisibilty() override {} 93 ~TestInkDropDelegateThatTracksVisibilty() override {}
94 94
95 // InkDropDelegate: 95 // InkDropDelegate:
96 void OnAction(InkDropState state) override { 96 void OnAction(InkDropState state) override {
97 switch (state) { 97 TestInkDropDelegate::OnAction(state);
98 switch (GetTargetInkDropState()) {
98 case InkDropState::ACTION_PENDING: 99 case InkDropState::ACTION_PENDING:
99 case InkDropState::ALTERNATE_ACTION_PENDING: 100 case InkDropState::ALTERNATE_ACTION_PENDING:
100 case InkDropState::ACTIVATED: 101 case InkDropState::ACTIVATED:
101 *ink_shown_ = true; 102 *ink_shown_ = true;
102 break; 103 break;
103 case InkDropState::HIDDEN: 104 case InkDropState::HIDDEN:
104 *ink_hidden_ = true; 105 *ink_hidden_ = true;
105 break; 106 break;
106 case InkDropState::ACTION_TRIGGERED: 107 case InkDropState::ACTION_TRIGGERED:
107 case InkDropState::ALTERNATE_ACTION_TRIGGERED: 108 case InkDropState::ALTERNATE_ACTION_TRIGGERED:
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 TestContextMenuController context_menu_controller; 442 TestContextMenuController context_menu_controller;
442 button()->set_context_menu_controller(&context_menu_controller); 443 button()->set_context_menu_controller(&context_menu_controller);
443 button()->set_hide_ink_drop_when_showing_context_menu(true); 444 button()->set_hide_ink_drop_when_showing_context_menu(true);
444 445
445 ink_drop_delegate->SetHovered(true); 446 ink_drop_delegate->SetHovered(true);
446 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); 447 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING);
447 448
448 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); 449 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE);
449 450
450 EXPECT_FALSE(ink_drop_delegate->is_hovered()); 451 EXPECT_FALSE(ink_drop_delegate->is_hovered());
451 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate->state()); 452 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate->GetTargetInkDropState());
452 } 453 }
453 454
454 TEST_F(CustomButtonTest, DontHideInkDropWhenShowingContextMenu) { 455 TEST_F(CustomButtonTest, DontHideInkDropWhenShowingContextMenu) {
455 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); 456 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate();
456 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate)); 457 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate));
457 TestContextMenuController context_menu_controller; 458 TestContextMenuController context_menu_controller;
458 button()->set_context_menu_controller(&context_menu_controller); 459 button()->set_context_menu_controller(&context_menu_controller);
459 button()->set_hide_ink_drop_when_showing_context_menu(false); 460 button()->set_hide_ink_drop_when_showing_context_menu(false);
460 461
461 ink_drop_delegate->SetHovered(true); 462 ink_drop_delegate->SetHovered(true);
462 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); 463 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING);
463 464
464 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); 465 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE);
465 466
466 EXPECT_TRUE(ink_drop_delegate->is_hovered()); 467 EXPECT_TRUE(ink_drop_delegate->is_hovered());
467 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop_delegate->state()); 468 EXPECT_EQ(InkDropState::ACTION_PENDING,
469 ink_drop_delegate->GetTargetInkDropState());
468 } 470 }
469 471
470 TEST_F(CustomButtonTest, InkDropAfterTryingToShowContextMenu) { 472 TEST_F(CustomButtonTest, InkDropAfterTryingToShowContextMenu) {
471 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); 473 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate();
472 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate)); 474 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate));
473 button()->set_context_menu_controller(nullptr); 475 button()->set_context_menu_controller(nullptr);
474 476
475 ink_drop_delegate->SetHovered(true); 477 ink_drop_delegate->SetHovered(true);
476 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); 478 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING);
477 479
478 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); 480 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE);
479 481
480 EXPECT_TRUE(ink_drop_delegate->is_hovered()); 482 EXPECT_TRUE(ink_drop_delegate->is_hovered());
481 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop_delegate->state()); 483 EXPECT_EQ(InkDropState::ACTION_PENDING,
484 ink_drop_delegate->GetTargetInkDropState());
482 } 485 }
483 486
484 } // namespace views 487 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/custom_button.cc ('k') | ui/views/controls/button/menu_button_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698