OLD | NEW |
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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "ui/base/dragdrop/drag_drop_types.h" | 9 #include "ui/base/dragdrop/drag_drop_types.h" |
10 #include "ui/events/test/event_generator.h" | 10 #include "ui/events/test/event_generator.h" |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 pressed_lock1.reset(); | 341 pressed_lock1.reset(); |
342 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); | 342 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); |
343 | 343 |
344 // Reseting the final lock should return the button's state to normal... | 344 // Reseting the final lock should return the button's state to normal... |
345 pressed_lock2.reset(); | 345 pressed_lock2.reset(); |
346 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); | 346 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); |
347 | 347 |
348 // ...And it should respond to mouse movement again. | 348 // ...And it should respond to mouse movement again. |
349 generator.MoveMouseTo(gfx::Point(10, 10)); | 349 generator.MoveMouseTo(gfx::Point(10, 10)); |
350 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); | 350 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); |
| 351 |
| 352 // Test that the button returns to the appropriate state after the press; if |
| 353 // the mouse ends over the button, the button should be hovered. |
| 354 pressed_lock1.reset(new MenuButton::PressedLock(button())); |
| 355 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); |
| 356 pressed_lock1.reset(); |
| 357 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); |
| 358 |
| 359 // If the button is disabled before the pressed lock, it should be disabled |
| 360 // after the pressed lock. |
| 361 button()->SetState(Button::STATE_DISABLED); |
| 362 pressed_lock1.reset(new MenuButton::PressedLock(button())); |
| 363 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); |
| 364 pressed_lock1.reset(); |
| 365 EXPECT_EQ(Button::STATE_DISABLED, button()->state()); |
| 366 |
| 367 generator.MoveMouseTo(gfx::Point(300, 10)); |
| 368 |
| 369 // Edge case: the button is disabled, a pressed lock is added, and then the |
| 370 // button is re-enabled. It should be enabled after the lock is removed. |
| 371 pressed_lock1.reset(new MenuButton::PressedLock(button())); |
| 372 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); |
| 373 button()->SetState(Button::STATE_NORMAL); |
| 374 pressed_lock1.reset(); |
| 375 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); |
351 } | 376 } |
352 | 377 |
353 // Test that the MenuButton does not become pressed if it can be dragged, until | 378 // Test that the MenuButton does not become pressed if it can be dragged, until |
354 // a release occurs. | 379 // a release occurs. |
355 TEST_F(MenuButtonTest, DraggableMenuButtonActivatesOnRelease) { | 380 TEST_F(MenuButtonTest, DraggableMenuButtonActivatesOnRelease) { |
356 TestMenuButtonListener menu_button_listener; | 381 TestMenuButtonListener menu_button_listener; |
357 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); | 382 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); |
358 TestDragController drag_controller; | 383 TestDragController drag_controller; |
359 button()->set_drag_controller(&drag_controller); | 384 button()->set_drag_controller(&drag_controller); |
360 | 385 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 generator.PressTouch(); | 439 generator.PressTouch(); |
415 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); | 440 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); |
416 | 441 |
417 generator.MoveTouch(gfx::Point(10, 30)); | 442 generator.MoveTouch(gfx::Point(10, 30)); |
418 generator.ReleaseTouch(); | 443 generator.ReleaseTouch(); |
419 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); | 444 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); |
420 EXPECT_EQ(nullptr, menu_button_listener.last_source()); | 445 EXPECT_EQ(nullptr, menu_button_listener.last_source()); |
421 } | 446 } |
422 | 447 |
423 } // namespace views | 448 } // namespace views |
OLD | NEW |