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 <memory> |
| 8 |
7 #include "base/macros.h" | 9 #include "base/macros.h" |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "build/build_config.h" | 11 #include "build/build_config.h" |
11 #include "ui/base/dragdrop/drag_drop_types.h" | 12 #include "ui/base/dragdrop/drag_drop_types.h" |
12 #include "ui/events/test/event_generator.h" | 13 #include "ui/events/test/event_generator.h" |
13 #include "ui/views/animation/test/test_ink_drop_delegate.h" | 14 #include "ui/views/animation/test/test_ink_drop_delegate.h" |
14 #include "ui/views/controls/button/menu_button_listener.h" | 15 #include "ui/views/controls/button/menu_button_listener.h" |
15 #include "ui/views/drag_controller.h" | 16 #include "ui/views/drag_controller.h" |
16 #include "ui/views/test/views_test_base.h" | 17 #include "ui/views/test/views_test_base.h" |
17 | 18 |
18 #if defined(USE_AURA) | 19 #if defined(USE_AURA) |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 98 |
98 widget_ = new Widget; | 99 widget_ = new Widget; |
99 Widget::InitParams params = | 100 Widget::InitParams params = |
100 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 101 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
101 params.bounds = gfx::Rect(0, 0, 200, 200); | 102 params.bounds = gfx::Rect(0, 0, 200, 200); |
102 widget_->Init(params); | 103 widget_->Init(params); |
103 } | 104 } |
104 | 105 |
105 Widget* widget_; | 106 Widget* widget_; |
106 TestMenuButton* button_; | 107 TestMenuButton* button_; |
107 scoped_ptr<ui::test::EventGenerator> generator_; | 108 std::unique_ptr<ui::test::EventGenerator> generator_; |
108 | 109 |
109 DISALLOW_COPY_AND_ASSIGN(MenuButtonTest); | 110 DISALLOW_COPY_AND_ASSIGN(MenuButtonTest); |
110 }; | 111 }; |
111 | 112 |
112 class TestButtonListener : public ButtonListener { | 113 class TestButtonListener : public ButtonListener { |
113 public: | 114 public: |
114 TestButtonListener() | 115 TestButtonListener() |
115 : last_sender_(nullptr), | 116 : last_sender_(nullptr), |
116 last_sender_state_(Button::STATE_NORMAL), | 117 last_sender_state_(Button::STATE_NORMAL), |
117 last_event_type_(ui::ET_UNKNOWN) {} | 118 last_event_type_(ui::ET_UNKNOWN) {} |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 const gfx::Point& point, | 178 const gfx::Point& point, |
178 const ui::Event* event) override { | 179 const ui::Event* event) override { |
179 pressed_lock_.reset(new MenuButton::PressedLock(menu_button_)); | 180 pressed_lock_.reset(new MenuButton::PressedLock(menu_button_)); |
180 if (release_lock_) | 181 if (release_lock_) |
181 pressed_lock_.reset(); | 182 pressed_lock_.reset(); |
182 } | 183 } |
183 | 184 |
184 private: | 185 private: |
185 MenuButton* menu_button_; | 186 MenuButton* menu_button_; |
186 | 187 |
187 scoped_ptr<MenuButton::PressedLock> pressed_lock_; | 188 std::unique_ptr<MenuButton::PressedLock> pressed_lock_; |
188 | 189 |
189 // The |pressed_lock_| will be released when true. | 190 // The |pressed_lock_| will be released when true. |
190 bool release_lock_; | 191 bool release_lock_; |
191 | 192 |
192 DISALLOW_COPY_AND_ASSIGN(PressStateMenuButtonListener); | 193 DISALLOW_COPY_AND_ASSIGN(PressStateMenuButtonListener); |
193 }; | 194 }; |
194 | 195 |
195 // Basic implementation of a DragController, to test input behaviour for | 196 // Basic implementation of a DragController, to test input behaviour for |
196 // MenuButtons that can be dragged. | 197 // MenuButtons that can be dragged. |
197 class TestDragController : public DragController { | 198 class TestDragController : public DragController { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 | 343 |
343 // Test that the MenuButton stays pressed while there are any PressedLocks. | 344 // Test that the MenuButton stays pressed while there are any PressedLocks. |
344 TEST_F(MenuButtonTest, ButtonStateForMenuButtonsWithPressedLocks) { | 345 TEST_F(MenuButtonTest, ButtonStateForMenuButtonsWithPressedLocks) { |
345 CreateMenuButtonWithNoListener(); | 346 CreateMenuButtonWithNoListener(); |
346 | 347 |
347 // Move the mouse over the button; the button should be in a hovered state. | 348 // Move the mouse over the button; the button should be in a hovered state. |
348 generator()->MoveMouseTo(gfx::Point(10, 10)); | 349 generator()->MoveMouseTo(gfx::Point(10, 10)); |
349 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); | 350 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); |
350 | 351 |
351 // Introduce a PressedLock, which should make the button pressed. | 352 // Introduce a PressedLock, which should make the button pressed. |
352 scoped_ptr<MenuButton::PressedLock> pressed_lock1( | 353 std::unique_ptr<MenuButton::PressedLock> pressed_lock1( |
353 new MenuButton::PressedLock(button())); | 354 new MenuButton::PressedLock(button())); |
354 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); | 355 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); |
355 | 356 |
356 // Even if we move the mouse outside of the button, it should remain pressed. | 357 // Even if we move the mouse outside of the button, it should remain pressed. |
357 generator()->MoveMouseTo(gfx::Point(300, 10)); | 358 generator()->MoveMouseTo(gfx::Point(300, 10)); |
358 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); | 359 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); |
359 | 360 |
360 // Creating a new lock should obviously keep the button pressed. | 361 // Creating a new lock should obviously keep the button pressed. |
361 scoped_ptr<MenuButton::PressedLock> pressed_lock2( | 362 std::unique_ptr<MenuButton::PressedLock> pressed_lock2( |
362 new MenuButton::PressedLock(button())); | 363 new MenuButton::PressedLock(button())); |
363 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); | 364 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); |
364 | 365 |
365 // The button should remain pressed while any locks are active. | 366 // The button should remain pressed while any locks are active. |
366 pressed_lock1.reset(); | 367 pressed_lock1.reset(); |
367 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); | 368 EXPECT_EQ(Button::STATE_PRESSED, button()->state()); |
368 | 369 |
369 // Reseting the final lock should return the button's state to normal... | 370 // Reseting the final lock should return the button's state to normal... |
370 pressed_lock2.reset(); | 371 pressed_lock2.reset(); |
371 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); | 372 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 button()->Activate(nullptr); | 477 button()->Activate(nullptr); |
477 | 478 |
478 EXPECT_EQ(InkDropState::DEACTIVATED, ink_drop_delegate.state()); | 479 EXPECT_EQ(InkDropState::DEACTIVATED, ink_drop_delegate.state()); |
479 } | 480 } |
480 | 481 |
481 TEST_F(MenuButtonTest, InkDropStateForMenuButtonsWithPressedLocks) { | 482 TEST_F(MenuButtonTest, InkDropStateForMenuButtonsWithPressedLocks) { |
482 CreateMenuButtonWithNoListener(); | 483 CreateMenuButtonWithNoListener(); |
483 TestInkDropDelegate ink_drop_delegate; | 484 TestInkDropDelegate ink_drop_delegate; |
484 button()->set_ink_drop_delegate(&ink_drop_delegate); | 485 button()->set_ink_drop_delegate(&ink_drop_delegate); |
485 | 486 |
486 scoped_ptr<MenuButton::PressedLock> pressed_lock1( | 487 std::unique_ptr<MenuButton::PressedLock> pressed_lock1( |
487 new MenuButton::PressedLock(button())); | 488 new MenuButton::PressedLock(button())); |
488 | 489 |
489 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.state()); | 490 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.state()); |
490 | 491 |
491 scoped_ptr<MenuButton::PressedLock> pressed_lock2( | 492 std::unique_ptr<MenuButton::PressedLock> pressed_lock2( |
492 new MenuButton::PressedLock(button())); | 493 new MenuButton::PressedLock(button())); |
493 | 494 |
494 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.state()); | 495 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.state()); |
495 | 496 |
496 pressed_lock1.reset(); | 497 pressed_lock1.reset(); |
497 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.state()); | 498 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.state()); |
498 | 499 |
499 pressed_lock2.reset(); | 500 pressed_lock2.reset(); |
500 EXPECT_EQ(InkDropState::DEACTIVATED, ink_drop_delegate.state()); | 501 EXPECT_EQ(InkDropState::DEACTIVATED, ink_drop_delegate.state()); |
501 } | 502 } |
502 | 503 |
503 // Verifies only one ink drop animation is triggered when multiple PressedLocks | 504 // Verifies only one ink drop animation is triggered when multiple PressedLocks |
504 // are attached to a MenuButton. | 505 // are attached to a MenuButton. |
505 TEST_F(MenuButtonTest, OneInkDropAnimationForReentrantPressedLocks) { | 506 TEST_F(MenuButtonTest, OneInkDropAnimationForReentrantPressedLocks) { |
506 CreateMenuButtonWithNoListener(); | 507 CreateMenuButtonWithNoListener(); |
507 TestInkDropDelegate ink_drop_delegate; | 508 TestInkDropDelegate ink_drop_delegate; |
508 button()->set_ink_drop_delegate(&ink_drop_delegate); | 509 button()->set_ink_drop_delegate(&ink_drop_delegate); |
509 | 510 |
510 scoped_ptr<MenuButton::PressedLock> pressed_lock1( | 511 std::unique_ptr<MenuButton::PressedLock> pressed_lock1( |
511 new MenuButton::PressedLock(button())); | 512 new MenuButton::PressedLock(button())); |
512 | 513 |
513 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.state()); | 514 EXPECT_EQ(InkDropState::ACTIVATED, ink_drop_delegate.state()); |
514 ink_drop_delegate.OnAction(InkDropState::ACTION_PENDING); | 515 ink_drop_delegate.OnAction(InkDropState::ACTION_PENDING); |
515 | 516 |
516 scoped_ptr<MenuButton::PressedLock> pressed_lock2( | 517 std::unique_ptr<MenuButton::PressedLock> pressed_lock2( |
517 new MenuButton::PressedLock(button())); | 518 new MenuButton::PressedLock(button())); |
518 | 519 |
519 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop_delegate.state()); | 520 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop_delegate.state()); |
520 } | 521 } |
521 | 522 |
522 // Verifies the InkDropState is left as ACTIVATED if a PressedLock is active | 523 // Verifies the InkDropState is left as ACTIVATED if a PressedLock is active |
523 // before another Activation occurs. | 524 // before another Activation occurs. |
524 TEST_F(MenuButtonTest, | 525 TEST_F(MenuButtonTest, |
525 InkDropStateForMenuButtonWithPressedLockBeforeActivation) { | 526 InkDropStateForMenuButtonWithPressedLockBeforeActivation) { |
526 TestMenuButtonListener menu_button_listener; | 527 TestMenuButtonListener menu_button_listener; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 generator()->MoveTouch(gfx::Point(10, 30)); | 604 generator()->MoveTouch(gfx::Point(10, 30)); |
604 generator()->ReleaseTouch(); | 605 generator()->ReleaseTouch(); |
605 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); | 606 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); |
606 EXPECT_EQ(nullptr, menu_button_listener.last_source()); | 607 EXPECT_EQ(nullptr, menu_button_listener.last_source()); |
607 } | 608 } |
608 | 609 |
609 #endif // !defined(OS_MACOSX) || defined(USE_AURA) | 610 #endif // !defined(OS_MACOSX) || defined(USE_AURA) |
610 | 611 |
611 } // namespace views | 612 } // namespace views |
612 } // namespace test | 613 } // namespace test |
OLD | NEW |