Chromium Code Reviews| 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 7a079fe7bba05f22de2c3e0b5209d16579e94b1b..c0a724a5d4c56724c93d93f10eca2277aa5d0fb6 100644 |
| --- a/ui/views/controls/button/custom_button_unittest.cc |
| +++ b/ui/views/controls/button/custom_button_unittest.cc |
| @@ -39,9 +39,17 @@ class TestCustomButton : public CustomButton, public ButtonListener { |
| notified_ = true; |
| } |
| + void OnClickCanceled(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; |
| + } |
| // CustomButton methods: |
| bool IsChildWidget() const override { return is_child_widget_; } |
| @@ -52,6 +60,7 @@ class TestCustomButton : public CustomButton, public ButtonListener { |
| private: |
| bool notified_ = false; |
| + bool notified_no_click_ = false; |
|
Peter Kasting
2015/12/01 02:03:18
Why not call these |pressed_| and |canceled_|? Th
varkha
2015/12/01 19:23:29
Done.
|
| bool is_child_widget_ = false; |
| bool focus_in_child_widget_ = false; |
| @@ -255,6 +264,38 @@ TEST_F(CustomButtonTest, HandleAccelerator) { |
| EXPECT_TRUE(button()->notified()); |
| } |
| +// Tests that OnClickCanceled 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) |