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

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

Issue 1411523009: Adds OnClickCanceled callback to views::Button (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds NotifyReleasedWithoutClick callback to views::Button (unit test) Created 5 years, 2 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 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)
« ui/views/controls/button/custom_button.cc ('K') | « ui/views/controls/button/custom_button.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698