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

Side by Side 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, 1 month 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 "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/base/layout.h" 8 #include "ui/base/layout.h"
9 #include "ui/events/event_utils.h" 9 #include "ui/events/event_utils.h"
10 #include "ui/gfx/screen.h" 10 #include "ui/gfx/screen.h"
(...skipping 21 matching lines...) Expand all
32 explicit TestCustomButton() 32 explicit TestCustomButton()
33 : CustomButton(this) { 33 : CustomButton(this) {
34 } 34 }
35 35
36 ~TestCustomButton() override {} 36 ~TestCustomButton() override {}
37 37
38 void ButtonPressed(Button* sender, const ui::Event& event) override { 38 void ButtonPressed(Button* sender, const ui::Event& event) override {
39 notified_ = true; 39 notified_ = true;
40 } 40 }
41 41
42 void NotifyMouseReleasedWithoutClick(const ui::Event& event) override {
43 notified_no_click_ = true;
44 }
45
42 bool notified() { return notified_; } 46 bool notified() { return notified_; }
47 bool notified_no_click() { return notified_no_click_; }
43 48
44 void Reset() { notified_ = false; } 49 void Reset() {
50 notified_ = false;
51 notified_no_click_ = false;
52 }
45 53
46 private: 54 private:
47 bool notified_ = false; 55 bool notified_ = false;
56 bool notified_no_click_ = false;
48 57
49 DISALLOW_COPY_AND_ASSIGN(TestCustomButton); 58 DISALLOW_COPY_AND_ASSIGN(TestCustomButton);
50 }; 59 };
51 60
52 class CustomButtonTest : public ViewsTestBase { 61 class CustomButtonTest : public ViewsTestBase {
53 public: 62 public:
54 CustomButtonTest() {} 63 CustomButtonTest() {}
55 ~CustomButtonTest() override {} 64 ~CustomButtonTest() override {}
56 65
57 void SetUp() override { 66 void SetUp() override {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 206
198 // The button should no longer notify on mouse release. 207 // The button should no longer notify on mouse release.
199 button()->Reset(); 208 button()->Reset();
200 button()->OnMouseReleased(ui::MouseEvent( 209 button()->OnMouseReleased(ui::MouseEvent(
201 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), 210 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(),
202 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); 211 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
203 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state()); 212 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state());
204 EXPECT_FALSE(button()->notified()); 213 EXPECT_FALSE(button()->notified());
205 } 214 }
206 215
216 // Tests that NotifyMouseReleasedWithoutClick gets called when NotifyClick is
217 // not expected anymore.
218 TEST_F(CustomButtonTest, NotifyActionNoClick) {
219 gfx::Point center(10, 10);
220
221 // By default the button should notify its listener on mouse release.
222 button()->OnMousePressed(ui::MouseEvent(
223 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(),
224 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON));
225 EXPECT_FALSE(button()->notified_no_click());
226
227 button()->OnMouseReleased(ui::MouseEvent(
228 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(),
229 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON));
230 EXPECT_TRUE(button()->notified_no_click());
231
232 // Set the notify action to its listener on mouse press.
233 button()->Reset();
234 button()->set_notify_action(CustomButton::NOTIFY_ON_PRESS);
235 button()->OnMousePressed(ui::MouseEvent(
236 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(),
237 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON));
238 EXPECT_TRUE(button()->notified_no_click());
239
240 // The button should no longer notify on mouse release.
241 button()->Reset();
242 button()->OnMouseReleased(ui::MouseEvent(
243 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(),
244 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON));
245 EXPECT_FALSE(button()->notified_no_click());
246 }
247
207 // No touch on desktop Mac. Tracked in http://crbug.com/445520. 248 // No touch on desktop Mac. Tracked in http://crbug.com/445520.
208 #if !defined(OS_MACOSX) || defined(USE_AURA) 249 #if !defined(OS_MACOSX) || defined(USE_AURA)
209 250
210 namespace { 251 namespace {
211 252
212 void PerformGesture(CustomButton* button, ui::EventType event_type) { 253 void PerformGesture(CustomButton* button, ui::EventType event_type) {
213 ui::GestureEventDetails gesture_details(event_type); 254 ui::GestureEventDetails gesture_details(event_type);
214 base::TimeDelta time_stamp = base::TimeDelta::FromMicroseconds(0); 255 base::TimeDelta time_stamp = base::TimeDelta::FromMicroseconds(0);
215 ui::GestureEvent gesture_event(0, 0, 0, time_stamp, gesture_details); 256 ui::GestureEvent gesture_event(0, 0, 0, time_stamp, gesture_details);
216 button->OnGestureEvent(&gesture_event); 257 button->OnGestureEvent(&gesture_event);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 EXPECT_FALSE(CustomButton::AsCustomButton(&label)); 301 EXPECT_FALSE(CustomButton::AsCustomButton(&label));
261 302
262 Link link(text); 303 Link link(text);
263 EXPECT_FALSE(CustomButton::AsCustomButton(&link)); 304 EXPECT_FALSE(CustomButton::AsCustomButton(&link));
264 305
265 Textfield textfield; 306 Textfield textfield;
266 EXPECT_FALSE(CustomButton::AsCustomButton(&textfield)); 307 EXPECT_FALSE(CustomButton::AsCustomButton(&textfield));
267 } 308 }
268 309
269 } // namespace views 310 } // namespace views
OLDNEW
« 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