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

Unified Diff: ui/views/controls/button/custom_button_unittest.cc

Issue 2070143003: Add MD ink drop ripple to app list button (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b612539_shelf_button_ripple
Patch Set: Updated tests 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/button/custom_button_unittest.cc
diff --git a/ui/views/controls/button/custom_button_unittest.cc b/ui/views/controls/button/custom_button_unittest.cc
index 74136c0c15e898ad393c6e5d0a23fba8938d5364..de3848493bc493431c5eaf02b482ea9f74e3e430 100644
--- a/ui/views/controls/button/custom_button_unittest.cc
+++ b/ui/views/controls/button/custom_button_unittest.cc
@@ -57,8 +57,9 @@ class TestContextMenuController : public ContextMenuController {
class TestCustomButton : public CustomButton, public ButtonListener {
public:
- explicit TestCustomButton()
+ explicit TestCustomButton(bool has_ink_drop_action_on_click)
: CustomButton(this) {
+ set_has_ink_drop_action_on_click(has_ink_drop_action_on_click);
}
~TestCustomButton() override {}
@@ -108,7 +109,7 @@ class CustomButtonTest : public ViewsTestBase {
widget_->Init(params);
widget_->Show();
- button_ = new TestCustomButton();
+ button_ = new TestCustomButton(false);
widget_->SetContentsView(button_);
}
@@ -117,9 +118,10 @@ class CustomButtonTest : public ViewsTestBase {
ViewsTestBase::TearDown();
}
- void CreateButtonWithInkDrop(std::unique_ptr<InkDrop> ink_drop) {
+ void CreateButtonWithInkDrop(std::unique_ptr<InkDrop> ink_drop,
+ bool has_ink_drop_action_on_click) {
delete button_;
- button_ = new TestCustomButton();
+ button_ = new TestCustomButton(has_ink_drop_action_on_click);
InkDropHostViewTestApi(button_).SetInkDrop(std::move(ink_drop));
widget_->SetContentsView(button_);
}
@@ -348,7 +350,7 @@ TEST_F(CustomButtonTest, AsCustomButton) {
// may enter a different ink drop state.
TEST_F(CustomButtonTest, ButtonClickTogglesInkDrop) {
TestInkDrop* ink_drop = new TestInkDrop();
- CreateButtonWithInkDrop(base::WrapUnique(ink_drop));
+ CreateButtonWithInkDrop(base::WrapUnique(ink_drop), false);
ui::test::EventGenerator generator(widget()->GetNativeWindow());
generator.set_current_location(gfx::Point(50, 50));
@@ -363,7 +365,7 @@ TEST_F(CustomButtonTest, ButtonClickTogglesInkDrop) {
// Releasing capture should also reset PRESSED button state to NORMAL.
TEST_F(CustomButtonTest, CaptureLossHidesInkDrop) {
TestInkDrop* ink_drop = new TestInkDrop();
- CreateButtonWithInkDrop(base::WrapUnique(ink_drop));
+ CreateButtonWithInkDrop(base::WrapUnique(ink_drop), false);
ui::test::EventGenerator generator(widget()->GetNativeWindow());
generator.set_current_location(gfx::Point(50, 50));
@@ -384,7 +386,7 @@ TEST_F(CustomButtonTest, CaptureLossHidesInkDrop) {
TEST_F(CustomButtonTest, HideInkDropWhenShowingContextMenu) {
TestInkDrop* ink_drop = new TestInkDrop();
- CreateButtonWithInkDrop(base::WrapUnique(ink_drop));
+ CreateButtonWithInkDrop(base::WrapUnique(ink_drop), false);
TestContextMenuController context_menu_controller;
button()->set_context_menu_controller(&context_menu_controller);
button()->set_hide_ink_drop_when_showing_context_menu(true);
@@ -400,7 +402,7 @@ TEST_F(CustomButtonTest, HideInkDropWhenShowingContextMenu) {
TEST_F(CustomButtonTest, DontHideInkDropWhenShowingContextMenu) {
TestInkDrop* ink_drop = new TestInkDrop();
- CreateButtonWithInkDrop(base::WrapUnique(ink_drop));
+ CreateButtonWithInkDrop(base::WrapUnique(ink_drop), false);
TestContextMenuController context_menu_controller;
button()->set_context_menu_controller(&context_menu_controller);
button()->set_hide_ink_drop_when_showing_context_menu(false);
@@ -418,7 +420,7 @@ TEST_F(CustomButtonTest, HideInkDropOnBlur) {
gfx::Point center(10, 10);
TestInkDrop* ink_drop = new TestInkDrop();
- CreateButtonWithInkDrop(base::WrapUnique(ink_drop));
+ CreateButtonWithInkDrop(base::WrapUnique(ink_drop), false);
button()->OnFocus();
@@ -438,7 +440,7 @@ TEST_F(CustomButtonTest, HideInkDropOnBlur) {
TEST_F(CustomButtonTest, InkDropAfterTryingToShowContextMenu) {
TestInkDrop* ink_drop = new TestInkDrop();
- CreateButtonWithInkDrop(base::WrapUnique(ink_drop));
+ CreateButtonWithInkDrop(base::WrapUnique(ink_drop), false);
button()->set_context_menu_controller(nullptr);
ink_drop->SetHovered(true);
@@ -455,7 +457,7 @@ TEST_F(CustomButtonTest, InkDropShowHideOnMouseDragged) {
gfx::Point oob(-1, -1);
TestInkDrop* ink_drop = new TestInkDrop();
- CreateButtonWithInkDrop(base::WrapUnique(ink_drop));
+ CreateButtonWithInkDrop(base::WrapUnique(ink_drop), false);
bruthig 2016/06/22 19:07:29 nit: Can you add 'button()->set_notify_action(Cust
mohsen 2016/06/23 15:49:56 Done.
button()->OnMousePressed(ui::MouseEvent(
ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(),
@@ -488,12 +490,54 @@ TEST_F(CustomButtonTest, InkDropShowHideOnMouseDragged) {
EXPECT_FALSE(button()->pressed());
}
+// Tests that when button is set to notify on press, dragging mouse out and back
+// does not change the ink drop state.
+TEST_F(CustomButtonTest, InkDropShowHideOnMouseDraggedNotifyOnPress) {
+ gfx::Point center(10, 10);
+ gfx::Point oob(-1, -1);
+
+ TestInkDrop* ink_drop = new TestInkDrop();
+ CreateButtonWithInkDrop(base::WrapUnique(ink_drop), true);
+ button()->set_notify_action(CustomButton::NOTIFY_ON_PRESS);
+
+ button()->OnMousePressed(ui::MouseEvent(
+ ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(),
+ ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
+
+ EXPECT_EQ(InkDropState::ACTION_TRIGGERED, ink_drop->GetTargetInkDropState());
+ EXPECT_TRUE(button()->pressed());
+
+ button()->OnMouseDragged(
+ ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(),
+ ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
+
+ EXPECT_EQ(InkDropState::ACTION_TRIGGERED, ink_drop->GetTargetInkDropState());
+
+ button()->OnMouseDragged(ui::MouseEvent(
+ ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(),
+ ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
+
+ EXPECT_EQ(InkDropState::ACTION_TRIGGERED, ink_drop->GetTargetInkDropState());
+
+ button()->OnMouseDragged(
+ ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(),
+ ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
+
+ EXPECT_EQ(InkDropState::ACTION_TRIGGERED, ink_drop->GetTargetInkDropState());
+
+ button()->OnMouseReleased(
+ ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(),
+ ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
+
+ EXPECT_EQ(InkDropState::ACTION_TRIGGERED, ink_drop->GetTargetInkDropState());
+}
+
TEST_F(CustomButtonTest, InkDropStaysHiddenWhileDragging) {
gfx::Point center(10, 10);
gfx::Point oob(-1, -1);
TestInkDrop* ink_drop = new TestInkDrop();
- CreateButtonWithInkDrop(base::WrapUnique(ink_drop));
+ CreateButtonWithInkDrop(base::WrapUnique(ink_drop), false);
button()->OnMousePressed(ui::MouseEvent(
ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(),

Powered by Google App Engine
This is Rietveld 408576698