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 e6e2ffc269aacdb3cf8cf7e16c0e7f7f31821558..5aabdb36fd01472596a0a82520a0f3e3865c5549 100644 |
--- a/ui/views/controls/button/custom_button_unittest.cc |
+++ b/ui/views/controls/button/custom_button_unittest.cc |
@@ -39,12 +39,21 @@ class TestCustomButton : public CustomButton, public ButtonListener { |
notified_ = true; |
} |
+ void NotifyMouseReleasedWithoutClick(const ui::Event& event) override { |
+ notified_no_click_ = true; |
+ } |
+ |
bool notified() { return notified_; } |
+ bool notified_no_click() { return notified_no_click_; } |
- void Reset() { notified_ = false; } |
+ void Reset() { |
+ notified_ = false; |
+ notified_no_click_ = false; |
+ } |
private: |
bool notified_ = false; |
+ bool notified_no_click_ = false; |
DISALLOW_COPY_AND_ASSIGN(TestCustomButton); |
}; |
@@ -204,6 +213,38 @@ TEST_F(CustomButtonTest, NotifyAction) { |
EXPECT_FALSE(button()->notified()); |
} |
+// Tests that NotifyMouseReleasedWithoutClick gets called when NotifyClick is |
+// not expected anymore. |
+TEST_F(CustomButtonTest, NotifyActionNoClick) { |
+ gfx::Point center(10, 10); |
+ |
+ // By default the button should notify its listener on mouse release. |
+ button()->OnMousePressed(ui::MouseEvent( |
+ ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
+ ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON)); |
+ EXPECT_FALSE(button()->notified_no_click()); |
+ |
+ button()->OnMouseReleased(ui::MouseEvent( |
+ ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), |
+ ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON)); |
+ EXPECT_TRUE(button()->notified_no_click()); |
+ |
+ // Set the notify action to its listener on mouse press. |
+ button()->Reset(); |
+ button()->set_notify_action(CustomButton::NOTIFY_ON_PRESS); |
+ button()->OnMousePressed(ui::MouseEvent( |
+ ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
+ ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON)); |
+ EXPECT_TRUE(button()->notified_no_click()); |
+ |
+ // The button should no longer notify on mouse release. |
+ button()->Reset(); |
+ button()->OnMouseReleased(ui::MouseEvent( |
+ ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), |
+ ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON)); |
+ EXPECT_FALSE(button()->notified_no_click()); |
+} |
+ |
// No touch on desktop Mac. Tracked in http://crbug.com/445520. |
#if !defined(OS_MACOSX) || defined(USE_AURA) |