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

Side by Side Diff: ui/views/controls/button/menu_button_unittest.cc

Issue 1670473002: MacViews: Fix views_unittests MenuButtonTest.{ActivateDropDownOnMouseClick,DraggableMenuButtonActiv… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/menu_button.h" 5 #include "ui/views/controls/button/menu_button.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "ui/base/dragdrop/drag_drop_types.h" 11 #include "ui/base/dragdrop/drag_drop_types.h"
12 #include "ui/events/test/event_generator.h" 12 #include "ui/events/test/event_generator.h"
13 #include "ui/views/controls/button/menu_button_listener.h" 13 #include "ui/views/controls/button/menu_button_listener.h"
14 #include "ui/views/drag_controller.h" 14 #include "ui/views/drag_controller.h"
15 #include "ui/views/test/views_test_base.h" 15 #include "ui/views/test/views_test_base.h"
16 16
17 #if defined(USE_AURA) 17 #if defined(USE_AURA)
18 #include "ui/events/event.h" 18 #include "ui/events/event.h"
19 #include "ui/events/event_handler.h" 19 #include "ui/events/event_handler.h"
20 #include "ui/wm/public/drag_drop_client.h" 20 #include "ui/wm/public/drag_drop_client.h"
21 #endif 21 #endif
22 22
23 using base::ASCIIToUTF16; 23 using base::ASCIIToUTF16;
24 24
25 namespace views { 25 namespace views {
26 26
27 class MenuButtonTest : public ViewsTestBase { 27 class MenuButtonTest : public ViewsTestBase {
28 public: 28 public:
29 MenuButtonTest() : widget_(nullptr), button_(nullptr) {} 29 MenuButtonTest() : widget_(nullptr), button_(nullptr), generator_(nullptr) {}
30 ~MenuButtonTest() override {} 30 ~MenuButtonTest() override {}
31 31
32 void TearDown() override { 32 void TearDown() override {
33 if (widget_ && !widget_->IsClosed()) 33 if (widget_ && !widget_->IsClosed())
34 widget_->Close(); 34 widget_->Close();
35 35
36 ViewsTestBase::TearDown(); 36 ViewsTestBase::TearDown();
37 } 37 }
38 38
39 Widget* widget() { return widget_; } 39 Widget* widget() { return widget_; }
40 MenuButton* button() { return button_; } 40 MenuButton* button() { return button_; }
41 ui::test::EventGenerator* generator() { return generator_; }
41 42
42 protected: 43 protected:
43 // Creates a MenuButton with no button listener. 44 // Creates a MenuButton with no button listener.
44 void CreateMenuButtonWithNoListener() { CreateMenuButton(nullptr, nullptr); } 45 void CreateMenuButtonWithNoListener() { CreateMenuButton(nullptr, nullptr); }
45 46
46 // Creates a MenuButton with a ButtonListener. In this case, the MenuButton 47 // Creates a MenuButton with a ButtonListener. In this case, the MenuButton
47 // acts like a regular button. 48 // acts like a regular button.
48 void CreateMenuButtonWithButtonListener(ButtonListener* button_listener) { 49 void CreateMenuButtonWithButtonListener(ButtonListener* button_listener) {
49 CreateMenuButton(button_listener, nullptr); 50 CreateMenuButton(button_listener, nullptr);
50 } 51 }
51 52
52 // Creates a MenuButton with a MenuButtonListener. In this case, when the 53 // Creates a MenuButton with a MenuButtonListener. In this case, when the
53 // MenuButton is pushed, it notifies the MenuButtonListener to open a 54 // MenuButton is pushed, it notifies the MenuButtonListener to open a
54 // drop-down menu. 55 // drop-down menu.
55 void CreateMenuButtonWithMenuButtonListener( 56 void CreateMenuButtonWithMenuButtonListener(
56 MenuButtonListener* menu_button_listener) { 57 MenuButtonListener* menu_button_listener) {
57 CreateMenuButton(nullptr, menu_button_listener); 58 CreateMenuButton(nullptr, menu_button_listener);
58 } 59 }
59 60
60 private: 61 private:
61 void CreateMenuButton(ButtonListener* button_listener, 62 void CreateMenuButton(ButtonListener* button_listener,
62 MenuButtonListener* menu_button_listener) { 63 MenuButtonListener* menu_button_listener) {
63 CreateWidget(); 64 CreateWidget();
65 generator_ = new ui::test::EventGenerator(GetContext(),
66 widget_->GetNativeWindow());
64 67
65 const base::string16 label(ASCIIToUTF16("button")); 68 const base::string16 label(ASCIIToUTF16("button"));
66 button_ = 69 button_ =
67 new MenuButton(button_listener, label, menu_button_listener, false); 70 new MenuButton(button_listener, label, menu_button_listener, false);
68 button_->SetBoundsRect(gfx::Rect(0, 0, 200, 20)); 71 button_->SetBoundsRect(gfx::Rect(0, 0, 200, 20));
69 widget_->SetContentsView(button_); 72 widget_->SetContentsView(button_);
70 73
71 widget_->Show(); 74 widget_->Show();
72 } 75 }
73 76
74 void CreateWidget() { 77 void CreateWidget() {
75 DCHECK(!widget_); 78 DCHECK(!widget_);
76 79
77 widget_ = new Widget; 80 widget_ = new Widget;
78 Widget::InitParams params = 81 Widget::InitParams params =
79 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); 82 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
80 params.bounds = gfx::Rect(0, 0, 200, 200); 83 params.bounds = gfx::Rect(0, 0, 200, 200);
81 widget_->Init(params); 84 widget_->Init(params);
82 } 85 }
83 86
84 Widget* widget_; 87 Widget* widget_;
85 MenuButton* button_; 88 MenuButton* button_;
89 ui::test::EventGenerator* generator_;
tapted 2016/02/04 23:27:09 this should be scoped_ptr.
Patti Lor 2016/02/08 06:03:26 Done.
86 }; 90 };
tapted 2016/02/04 23:27:08 nit: there should be a DISALLOW_COPY_AND_ASSIGN(Me
Patti Lor 2016/02/08 06:03:26 Done.
87 91
88 class TestButtonListener : public ButtonListener { 92 class TestButtonListener : public ButtonListener {
89 public: 93 public:
90 TestButtonListener() 94 TestButtonListener()
91 : last_sender_(nullptr), 95 : last_sender_(nullptr),
92 last_sender_state_(Button::STATE_NORMAL), 96 last_sender_state_(Button::STATE_NORMAL),
93 last_event_type_(ui::ET_UNKNOWN) {} 97 last_event_type_(ui::ET_UNKNOWN) {}
94 ~TestButtonListener() override {} 98 ~TestButtonListener() override {}
95 99
96 void ButtonPressed(Button* sender, const ui::Event& event) override { 100 void ButtonPressed(Button* sender, const ui::Event& event) override {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 private: 271 private:
268 DISALLOW_COPY_AND_ASSIGN(TestShowSiblingButtonListener); 272 DISALLOW_COPY_AND_ASSIGN(TestShowSiblingButtonListener);
269 }; 273 };
270 274
271 // Tests if the listener is notified correctly, when a mouse click happens on a 275 // Tests if the listener is notified correctly, when a mouse click happens on a
272 // MenuButton that has a regular ButtonListener. 276 // MenuButton that has a regular ButtonListener.
273 TEST_F(MenuButtonTest, ActivateNonDropDownOnMouseClick) { 277 TEST_F(MenuButtonTest, ActivateNonDropDownOnMouseClick) {
274 TestButtonListener button_listener; 278 TestButtonListener button_listener;
275 CreateMenuButtonWithButtonListener(&button_listener); 279 CreateMenuButtonWithButtonListener(&button_listener);
276 280
277 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); 281 generator()->set_current_location(gfx::Point(10, 10));
278 282 generator()->ClickLeftButton();
279 generator.set_current_location(gfx::Point(10, 10));
280 generator.ClickLeftButton();
281 283
282 // Check that MenuButton has notified the listener on mouse-released event, 284 // Check that MenuButton has notified the listener on mouse-released event,
283 // while it was in hovered state. 285 // while it was in hovered state.
284 EXPECT_EQ(button(), button_listener.last_sender()); 286 EXPECT_EQ(button(), button_listener.last_sender());
285 EXPECT_EQ(ui::ET_MOUSE_RELEASED, button_listener.last_event_type()); 287 EXPECT_EQ(ui::ET_MOUSE_RELEASED, button_listener.last_event_type());
286 EXPECT_EQ(Button::STATE_HOVERED, button_listener.last_sender_state()); 288 EXPECT_EQ(Button::STATE_HOVERED, button_listener.last_sender_state());
287 } 289 }
288 290
289 // Tests if the listener is notified correctly when a mouse click happens on a 291 // Tests if the listener is notified correctly when a mouse click happens on a
290 // MenuButton that has a MenuButtonListener. 292 // MenuButton that has a MenuButtonListener.
291 TEST_F(MenuButtonTest, ActivateDropDownOnMouseClick) { 293 TEST_F(MenuButtonTest, ActivateDropDownOnMouseClick) {
292 TestMenuButtonListener menu_button_listener; 294 TestMenuButtonListener menu_button_listener;
293 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 295 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
294 296
295 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); 297 generator()->set_current_location(gfx::Point(10, 10));
296 298 generator()->ClickLeftButton();
297 generator.set_current_location(gfx::Point(10, 10));
298 generator.ClickLeftButton();
299 299
300 // Check that MenuButton has notified the listener, while it was in pressed 300 // Check that MenuButton has notified the listener, while it was in pressed
301 // state. 301 // state.
302 EXPECT_EQ(button(), menu_button_listener.last_source()); 302 EXPECT_EQ(button(), menu_button_listener.last_source());
303 EXPECT_EQ(Button::STATE_HOVERED, menu_button_listener.last_source_state()); 303 EXPECT_EQ(Button::STATE_HOVERED, menu_button_listener.last_source_state());
304 } 304 }
305 305
306 // Test that the MenuButton stays pressed while there are any PressedLocks. 306 // Test that the MenuButton stays pressed while there are any PressedLocks.
307 TEST_F(MenuButtonTest, MenuButtonPressedLock) { 307 TEST_F(MenuButtonTest, MenuButtonPressedLock) {
308 CreateMenuButtonWithNoListener(); 308 CreateMenuButtonWithNoListener();
309 309
310 // Move the mouse over the button; the button should be in a hovered state. 310 // Move the mouse over the button; the button should be in a hovered state.
311 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); 311 generator()->MoveMouseTo(gfx::Point(10, 10));
312 generator.MoveMouseTo(gfx::Point(10, 10));
313 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); 312 EXPECT_EQ(Button::STATE_HOVERED, button()->state());
314 313
315 // Introduce a PressedLock, which should make the button pressed. 314 // Introduce a PressedLock, which should make the button pressed.
316 scoped_ptr<MenuButton::PressedLock> pressed_lock1( 315 scoped_ptr<MenuButton::PressedLock> pressed_lock1(
317 new MenuButton::PressedLock(button())); 316 new MenuButton::PressedLock(button()));
318 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); 317 EXPECT_EQ(Button::STATE_PRESSED, button()->state());
319 318
320 // Even if we move the mouse outside of the button, it should remain pressed. 319 // Even if we move the mouse outside of the button, it should remain pressed.
321 generator.MoveMouseTo(gfx::Point(300, 10)); 320 generator()->MoveMouseTo(gfx::Point(300, 10));
322 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); 321 EXPECT_EQ(Button::STATE_PRESSED, button()->state());
323 322
324 // Creating a new lock should obviously keep the button pressed. 323 // Creating a new lock should obviously keep the button pressed.
325 scoped_ptr<MenuButton::PressedLock> pressed_lock2( 324 scoped_ptr<MenuButton::PressedLock> pressed_lock2(
326 new MenuButton::PressedLock(button())); 325 new MenuButton::PressedLock(button()));
327 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); 326 EXPECT_EQ(Button::STATE_PRESSED, button()->state());
328 327
329 // The button should remain pressed while any locks are active. 328 // The button should remain pressed while any locks are active.
330 pressed_lock1.reset(); 329 pressed_lock1.reset();
331 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); 330 EXPECT_EQ(Button::STATE_PRESSED, button()->state());
332 331
333 // Reseting the final lock should return the button's state to normal... 332 // Reseting the final lock should return the button's state to normal...
334 pressed_lock2.reset(); 333 pressed_lock2.reset();
335 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); 334 EXPECT_EQ(Button::STATE_NORMAL, button()->state());
336 335
337 // ...And it should respond to mouse movement again. 336 // ...And it should respond to mouse movement again.
338 generator.MoveMouseTo(gfx::Point(10, 10)); 337 generator()->MoveMouseTo(gfx::Point(10, 10));
339 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); 338 EXPECT_EQ(Button::STATE_HOVERED, button()->state());
340 339
341 // Test that the button returns to the appropriate state after the press; if 340 // Test that the button returns to the appropriate state after the press; if
342 // the mouse ends over the button, the button should be hovered. 341 // the mouse ends over the button, the button should be hovered.
343 pressed_lock1.reset(new MenuButton::PressedLock(button())); 342 pressed_lock1.reset(new MenuButton::PressedLock(button()));
344 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); 343 EXPECT_EQ(Button::STATE_PRESSED, button()->state());
345 pressed_lock1.reset(); 344 pressed_lock1.reset();
346 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); 345 EXPECT_EQ(Button::STATE_HOVERED, button()->state());
347 346
348 // If the button is disabled before the pressed lock, it should be disabled 347 // If the button is disabled before the pressed lock, it should be disabled
349 // after the pressed lock. 348 // after the pressed lock.
350 button()->SetState(Button::STATE_DISABLED); 349 button()->SetState(Button::STATE_DISABLED);
351 pressed_lock1.reset(new MenuButton::PressedLock(button())); 350 pressed_lock1.reset(new MenuButton::PressedLock(button()));
352 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); 351 EXPECT_EQ(Button::STATE_PRESSED, button()->state());
353 pressed_lock1.reset(); 352 pressed_lock1.reset();
354 EXPECT_EQ(Button::STATE_DISABLED, button()->state()); 353 EXPECT_EQ(Button::STATE_DISABLED, button()->state());
355 354
356 generator.MoveMouseTo(gfx::Point(300, 10)); 355 generator()->MoveMouseTo(gfx::Point(300, 10));
357 356
358 // Edge case: the button is disabled, a pressed lock is added, and then the 357 // Edge case: the button is disabled, a pressed lock is added, and then the
359 // button is re-enabled. It should be enabled after the lock is removed. 358 // button is re-enabled. It should be enabled after the lock is removed.
360 pressed_lock1.reset(new MenuButton::PressedLock(button())); 359 pressed_lock1.reset(new MenuButton::PressedLock(button()));
361 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); 360 EXPECT_EQ(Button::STATE_PRESSED, button()->state());
362 button()->SetState(Button::STATE_NORMAL); 361 button()->SetState(Button::STATE_NORMAL);
363 pressed_lock1.reset(); 362 pressed_lock1.reset();
364 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); 363 EXPECT_EQ(Button::STATE_NORMAL, button()->state());
365 } 364 }
366 365
367 // Test that if a sibling menu is shown, the original menu button releases its 366 // Test that if a sibling menu is shown, the original menu button releases its
368 // PressedLock. 367 // PressedLock.
369 TEST_F(MenuButtonTest, PressedStateWithSiblingMenu) { 368 TEST_F(MenuButtonTest, PressedStateWithSiblingMenu) {
370 TestShowSiblingButtonListener listener; 369 TestShowSiblingButtonListener listener;
371 CreateMenuButtonWithMenuButtonListener(&listener); 370 CreateMenuButtonWithMenuButtonListener(&listener);
372 371
373 // Move the mouse over the button; the button should be in a hovered state. 372 // Move the mouse over the button; the button should be in a hovered state.
374 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); 373 generator()->MoveMouseTo(gfx::Point(10, 10));
375 generator.MoveMouseTo(gfx::Point(10, 10));
376 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); 374 EXPECT_EQ(Button::STATE_HOVERED, button()->state());
377 generator.ClickLeftButton(); 375 generator()->ClickLeftButton();
378 // Test is continued in TestShowSiblingButtonListener::OnMenuButtonClicked(). 376 // Test is continued in TestShowSiblingButtonListener::OnMenuButtonClicked().
379 } 377 }
380 378
381 // Test that the MenuButton does not become pressed if it can be dragged, until 379 // Test that the MenuButton does not become pressed if it can be dragged, until
382 // a release occurs. 380 // a release occurs.
383 TEST_F(MenuButtonTest, DraggableMenuButtonActivatesOnRelease) { 381 TEST_F(MenuButtonTest, DraggableMenuButtonActivatesOnRelease) {
384 TestMenuButtonListener menu_button_listener; 382 TestMenuButtonListener menu_button_listener;
385 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 383 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
386 TestDragController drag_controller; 384 TestDragController drag_controller;
387 button()->set_drag_controller(&drag_controller); 385 button()->set_drag_controller(&drag_controller);
388 386
389 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); 387 generator()->set_current_location(gfx::Point(10, 10));
390 388 generator()->PressLeftButton();
391 generator.set_current_location(gfx::Point(10, 10));
392 generator.PressLeftButton();
393 EXPECT_EQ(nullptr, menu_button_listener.last_source()); 389 EXPECT_EQ(nullptr, menu_button_listener.last_source());
394 390
395 generator.ReleaseLeftButton(); 391 generator()->ReleaseLeftButton();
396 EXPECT_EQ(button(), menu_button_listener.last_source()); 392 EXPECT_EQ(button(), menu_button_listener.last_source());
397 EXPECT_EQ(Button::STATE_HOVERED, menu_button_listener.last_source_state()); 393 EXPECT_EQ(Button::STATE_HOVERED, menu_button_listener.last_source_state());
398 } 394 }
399 395
400 #if defined(USE_AURA) 396 #if defined(USE_AURA)
401 397
402 // Tests that the MenuButton does not become pressed if it can be dragged, and a 398 // Tests that the MenuButton does not become pressed if it can be dragged, and a
403 // DragDropClient is processing the events. 399 // DragDropClient is processing the events.
404 TEST_F(MenuButtonTest, DraggableMenuButtonDoesNotActivateOnDrag) { 400 TEST_F(MenuButtonTest, DraggableMenuButtonDoesNotActivateOnDrag) {
405 TestMenuButtonListener menu_button_listener; 401 TestMenuButtonListener menu_button_listener;
406 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 402 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
407 TestDragController drag_controller; 403 TestDragController drag_controller;
408 button()->set_drag_controller(&drag_controller); 404 button()->set_drag_controller(&drag_controller);
409 405
410 TestDragDropClient drag_client; 406 TestDragDropClient drag_client;
411 SetDragDropClient(GetContext(), &drag_client); 407 SetDragDropClient(GetContext(), &drag_client);
412 button()->PrependPreTargetHandler(&drag_client); 408 button()->PrependPreTargetHandler(&drag_client);
413 409
414 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); 410 generator()->set_current_location(gfx::Point(10, 10));
415 generator.set_current_location(gfx::Point(10, 10)); 411 generator()->DragMouseBy(10, 0);
416 generator.DragMouseBy(10, 0);
417 EXPECT_EQ(nullptr, menu_button_listener.last_source()); 412 EXPECT_EQ(nullptr, menu_button_listener.last_source());
418 EXPECT_EQ(Button::STATE_NORMAL, menu_button_listener.last_source_state()); 413 EXPECT_EQ(Button::STATE_NORMAL, menu_button_listener.last_source_state());
419 } 414 }
420 415
421 #endif // USE_AURA 416 #endif // USE_AURA
422 417
423 // No touch on desktop Mac. Tracked in http://crbug.com/445520. 418 // No touch on desktop Mac. Tracked in http://crbug.com/445520.
424 #if !defined(OS_MACOSX) || defined(USE_AURA) 419 #if !defined(OS_MACOSX) || defined(USE_AURA)
425 420
426 // Tests if the listener is notified correctly when a gesture tap happens on a 421 // Tests if the listener is notified correctly when a gesture tap happens on a
427 // MenuButton that has a regular ButtonListener. 422 // MenuButton that has a regular ButtonListener.
428 TEST_F(MenuButtonTest, ActivateNonDropDownOnGestureTap) { 423 TEST_F(MenuButtonTest, ActivateNonDropDownOnGestureTap) {
429 TestButtonListener button_listener; 424 TestButtonListener button_listener;
430 CreateMenuButtonWithButtonListener(&button_listener); 425 CreateMenuButtonWithButtonListener(&button_listener);
431 426
432 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow());
433
434 // Move the mouse outside the menu button so that it doesn't impact the 427 // Move the mouse outside the menu button so that it doesn't impact the
435 // button state. 428 // button state.
436 generator.MoveMouseTo(400, 400); 429 generator()->MoveMouseTo(400, 400);
437 EXPECT_FALSE(button()->IsMouseHovered()); 430 EXPECT_FALSE(button()->IsMouseHovered());
438 431
439 generator.GestureTapAt(gfx::Point(10, 10)); 432 generator()->GestureTapAt(gfx::Point(10, 10));
440 433
441 // Check that MenuButton has notified the listener on gesture tap event, while 434 // Check that MenuButton has notified the listener on gesture tap event, while
442 // it was in hovered state. 435 // it was in hovered state.
443 EXPECT_EQ(button(), button_listener.last_sender()); 436 EXPECT_EQ(button(), button_listener.last_sender());
444 EXPECT_EQ(ui::ET_GESTURE_TAP, button_listener.last_event_type()); 437 EXPECT_EQ(ui::ET_GESTURE_TAP, button_listener.last_event_type());
445 EXPECT_EQ(Button::STATE_HOVERED, button_listener.last_sender_state()); 438 EXPECT_EQ(Button::STATE_HOVERED, button_listener.last_sender_state());
446 439
447 // The button should go back to it's normal state since the gesture ended. 440 // The button should go back to it's normal state since the gesture ended.
448 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); 441 EXPECT_EQ(Button::STATE_NORMAL, button()->state());
449 } 442 }
450 443
451 // Tests if the listener is notified correctly when a gesture tap happens on a 444 // Tests if the listener is notified correctly when a gesture tap happens on a
452 // MenuButton that has a MenuButtonListener. 445 // MenuButton that has a MenuButtonListener.
453 TEST_F(MenuButtonTest, ActivateDropDownOnGestureTap) { 446 TEST_F(MenuButtonTest, ActivateDropDownOnGestureTap) {
454 TestMenuButtonListener menu_button_listener; 447 TestMenuButtonListener menu_button_listener;
455 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 448 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
456 449
457 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow());
458
459 // Move the mouse outside the menu button so that it doesn't impact the 450 // Move the mouse outside the menu button so that it doesn't impact the
460 // button state. 451 // button state.
461 generator.MoveMouseTo(400, 400); 452 generator()->MoveMouseTo(400, 400);
462 EXPECT_FALSE(button()->IsMouseHovered()); 453 EXPECT_FALSE(button()->IsMouseHovered());
463 454
464 generator.GestureTapAt(gfx::Point(10, 10)); 455 generator()->GestureTapAt(gfx::Point(10, 10));
465 456
466 // Check that MenuButton has notified the listener, while it was in pressed 457 // Check that MenuButton has notified the listener, while it was in pressed
467 // state. 458 // state.
468 EXPECT_EQ(button(), menu_button_listener.last_source()); 459 EXPECT_EQ(button(), menu_button_listener.last_source());
469 EXPECT_EQ(Button::STATE_HOVERED, menu_button_listener.last_source_state()); 460 EXPECT_EQ(Button::STATE_HOVERED, menu_button_listener.last_source_state());
470 461
471 // The button should go back to it's normal state since the gesture ended. 462 // The button should go back to it's normal state since the gesture ended.
472 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); 463 EXPECT_EQ(Button::STATE_NORMAL, button()->state());
473 } 464 }
474 465
475 // Tests that the button enters a hovered state upon a tap down, before becoming 466 // Tests that the button enters a hovered state upon a tap down, before becoming
476 // pressed at activation. 467 // pressed at activation.
477 TEST_F(MenuButtonTest, TouchFeedbackDuringTap) { 468 TEST_F(MenuButtonTest, TouchFeedbackDuringTap) {
478 TestMenuButtonListener menu_button_listener; 469 TestMenuButtonListener menu_button_listener;
479 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 470 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
480 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); 471 generator()->set_current_location(gfx::Point(10, 10));
481 generator.set_current_location(gfx::Point(10, 10)); 472 generator()->PressTouch();
482 generator.PressTouch();
483 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); 473 EXPECT_EQ(Button::STATE_HOVERED, button()->state());
484 474
485 generator.ReleaseTouch(); 475 generator()->ReleaseTouch();
486 EXPECT_EQ(Button::STATE_HOVERED, menu_button_listener.last_source_state()); 476 EXPECT_EQ(Button::STATE_HOVERED, menu_button_listener.last_source_state());
487 } 477 }
488 478
489 // Tests that a move event that exits the button returns it to the normal state, 479 // Tests that a move event that exits the button returns it to the normal state,
490 // and that the button did not activate the listener. 480 // and that the button did not activate the listener.
491 TEST_F(MenuButtonTest, TouchFeedbackDuringTapCancel) { 481 TEST_F(MenuButtonTest, TouchFeedbackDuringTapCancel) {
492 TestMenuButtonListener menu_button_listener; 482 TestMenuButtonListener menu_button_listener;
493 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); 483 CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
494 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); 484 generator()->set_current_location(gfx::Point(10, 10));
495 generator.set_current_location(gfx::Point(10, 10)); 485 generator()->PressTouch();
496 generator.PressTouch();
497 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); 486 EXPECT_EQ(Button::STATE_HOVERED, button()->state());
498 487
499 generator.MoveTouch(gfx::Point(10, 30)); 488 generator()->MoveTouch(gfx::Point(10, 30));
500 generator.ReleaseTouch(); 489 generator()->ReleaseTouch();
501 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); 490 EXPECT_EQ(Button::STATE_NORMAL, button()->state());
502 EXPECT_EQ(nullptr, menu_button_listener.last_source()); 491 EXPECT_EQ(nullptr, menu_button_listener.last_source());
503 } 492 }
504 493
505 #endif // !defined(OS_MACOSX) || defined(USE_AURA) 494 #endif // !defined(OS_MACOSX) || defined(USE_AURA)
506 495
507 } // namespace views 496 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698