Chromium Code Reviews| Index: ui/views/controls/button/menu_button_unittest.cc |
| diff --git a/ui/views/controls/button/menu_button_unittest.cc b/ui/views/controls/button/menu_button_unittest.cc |
| index 8d554c9e5f7a637ad32507959ce33fbbc9032fb1..5aea0caccad1810602eaeece8f60d1882bb33aac 100644 |
| --- a/ui/views/controls/button/menu_button_unittest.cc |
| +++ b/ui/views/controls/button/menu_button_unittest.cc |
| @@ -26,7 +26,7 @@ namespace views { |
| class MenuButtonTest : public ViewsTestBase { |
| public: |
| - MenuButtonTest() : widget_(nullptr), button_(nullptr) {} |
| + MenuButtonTest() : widget_(nullptr), button_(nullptr), generator_(nullptr) {} |
| ~MenuButtonTest() override {} |
| void TearDown() override { |
| @@ -38,6 +38,7 @@ class MenuButtonTest : public ViewsTestBase { |
| Widget* widget() { return widget_; } |
| MenuButton* button() { return button_; } |
| + ui::test::EventGenerator* generator() { return generator_; } |
| protected: |
| // Creates a MenuButton with no button listener. |
| @@ -61,6 +62,8 @@ class MenuButtonTest : public ViewsTestBase { |
| void CreateMenuButton(ButtonListener* button_listener, |
| MenuButtonListener* menu_button_listener) { |
| CreateWidget(); |
| + generator_ = new ui::test::EventGenerator(GetContext(), |
| + widget_->GetNativeWindow()); |
| const base::string16 label(ASCIIToUTF16("button")); |
| button_ = |
| @@ -83,6 +86,7 @@ class MenuButtonTest : public ViewsTestBase { |
| Widget* widget_; |
| MenuButton* button_; |
| + 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.
|
| }; |
|
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.
|
| class TestButtonListener : public ButtonListener { |
| @@ -274,10 +278,8 @@ TEST_F(MenuButtonTest, ActivateNonDropDownOnMouseClick) { |
| TestButtonListener button_listener; |
| CreateMenuButtonWithButtonListener(&button_listener); |
| - ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); |
| - |
| - generator.set_current_location(gfx::Point(10, 10)); |
| - generator.ClickLeftButton(); |
| + generator()->set_current_location(gfx::Point(10, 10)); |
| + generator()->ClickLeftButton(); |
| // Check that MenuButton has notified the listener on mouse-released event, |
| // while it was in hovered state. |
| @@ -292,10 +294,8 @@ TEST_F(MenuButtonTest, ActivateDropDownOnMouseClick) { |
| TestMenuButtonListener menu_button_listener; |
| CreateMenuButtonWithMenuButtonListener(&menu_button_listener); |
| - ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); |
| - |
| - generator.set_current_location(gfx::Point(10, 10)); |
| - generator.ClickLeftButton(); |
| + generator()->set_current_location(gfx::Point(10, 10)); |
| + generator()->ClickLeftButton(); |
| // Check that MenuButton has notified the listener, while it was in pressed |
| // state. |
| @@ -308,8 +308,7 @@ TEST_F(MenuButtonTest, MenuButtonPressedLock) { |
| CreateMenuButtonWithNoListener(); |
| // Move the mouse over the button; the button should be in a hovered state. |
| - ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); |
| - generator.MoveMouseTo(gfx::Point(10, 10)); |
| + generator()->MoveMouseTo(gfx::Point(10, 10)); |
| EXPECT_EQ(Button::STATE_HOVERED, button()->state()); |
| // Introduce a PressedLock, which should make the button pressed. |
| @@ -318,7 +317,7 @@ TEST_F(MenuButtonTest, MenuButtonPressedLock) { |
| EXPECT_EQ(Button::STATE_PRESSED, button()->state()); |
| // Even if we move the mouse outside of the button, it should remain pressed. |
| - generator.MoveMouseTo(gfx::Point(300, 10)); |
| + generator()->MoveMouseTo(gfx::Point(300, 10)); |
| EXPECT_EQ(Button::STATE_PRESSED, button()->state()); |
| // Creating a new lock should obviously keep the button pressed. |
| @@ -335,7 +334,7 @@ TEST_F(MenuButtonTest, MenuButtonPressedLock) { |
| EXPECT_EQ(Button::STATE_NORMAL, button()->state()); |
| // ...And it should respond to mouse movement again. |
| - generator.MoveMouseTo(gfx::Point(10, 10)); |
| + generator()->MoveMouseTo(gfx::Point(10, 10)); |
| EXPECT_EQ(Button::STATE_HOVERED, button()->state()); |
| // Test that the button returns to the appropriate state after the press; if |
| @@ -353,7 +352,7 @@ TEST_F(MenuButtonTest, MenuButtonPressedLock) { |
| pressed_lock1.reset(); |
| EXPECT_EQ(Button::STATE_DISABLED, button()->state()); |
| - generator.MoveMouseTo(gfx::Point(300, 10)); |
| + generator()->MoveMouseTo(gfx::Point(300, 10)); |
| // Edge case: the button is disabled, a pressed lock is added, and then the |
| // button is re-enabled. It should be enabled after the lock is removed. |
| @@ -371,10 +370,9 @@ TEST_F(MenuButtonTest, PressedStateWithSiblingMenu) { |
| CreateMenuButtonWithMenuButtonListener(&listener); |
| // Move the mouse over the button; the button should be in a hovered state. |
| - ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); |
| - generator.MoveMouseTo(gfx::Point(10, 10)); |
| + generator()->MoveMouseTo(gfx::Point(10, 10)); |
| EXPECT_EQ(Button::STATE_HOVERED, button()->state()); |
| - generator.ClickLeftButton(); |
| + generator()->ClickLeftButton(); |
| // Test is continued in TestShowSiblingButtonListener::OnMenuButtonClicked(). |
| } |
| @@ -386,13 +384,11 @@ TEST_F(MenuButtonTest, DraggableMenuButtonActivatesOnRelease) { |
| TestDragController drag_controller; |
| button()->set_drag_controller(&drag_controller); |
| - ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); |
| - |
| - generator.set_current_location(gfx::Point(10, 10)); |
| - generator.PressLeftButton(); |
| + generator()->set_current_location(gfx::Point(10, 10)); |
| + generator()->PressLeftButton(); |
| EXPECT_EQ(nullptr, menu_button_listener.last_source()); |
| - generator.ReleaseLeftButton(); |
| + generator()->ReleaseLeftButton(); |
| EXPECT_EQ(button(), menu_button_listener.last_source()); |
| EXPECT_EQ(Button::STATE_HOVERED, menu_button_listener.last_source_state()); |
| } |
| @@ -411,9 +407,8 @@ TEST_F(MenuButtonTest, DraggableMenuButtonDoesNotActivateOnDrag) { |
| SetDragDropClient(GetContext(), &drag_client); |
| button()->PrependPreTargetHandler(&drag_client); |
| - ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); |
| - generator.set_current_location(gfx::Point(10, 10)); |
| - generator.DragMouseBy(10, 0); |
| + generator()->set_current_location(gfx::Point(10, 10)); |
| + generator()->DragMouseBy(10, 0); |
| EXPECT_EQ(nullptr, menu_button_listener.last_source()); |
| EXPECT_EQ(Button::STATE_NORMAL, menu_button_listener.last_source_state()); |
| } |
| @@ -429,14 +424,12 @@ TEST_F(MenuButtonTest, ActivateNonDropDownOnGestureTap) { |
| TestButtonListener button_listener; |
| CreateMenuButtonWithButtonListener(&button_listener); |
| - ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); |
| - |
| // Move the mouse outside the menu button so that it doesn't impact the |
| // button state. |
| - generator.MoveMouseTo(400, 400); |
| + generator()->MoveMouseTo(400, 400); |
| EXPECT_FALSE(button()->IsMouseHovered()); |
| - generator.GestureTapAt(gfx::Point(10, 10)); |
| + generator()->GestureTapAt(gfx::Point(10, 10)); |
| // Check that MenuButton has notified the listener on gesture tap event, while |
| // it was in hovered state. |
| @@ -454,14 +447,12 @@ TEST_F(MenuButtonTest, ActivateDropDownOnGestureTap) { |
| TestMenuButtonListener menu_button_listener; |
| CreateMenuButtonWithMenuButtonListener(&menu_button_listener); |
| - ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); |
| - |
| // Move the mouse outside the menu button so that it doesn't impact the |
| // button state. |
| - generator.MoveMouseTo(400, 400); |
| + generator()->MoveMouseTo(400, 400); |
| EXPECT_FALSE(button()->IsMouseHovered()); |
| - generator.GestureTapAt(gfx::Point(10, 10)); |
| + generator()->GestureTapAt(gfx::Point(10, 10)); |
| // Check that MenuButton has notified the listener, while it was in pressed |
| // state. |
| @@ -477,12 +468,11 @@ TEST_F(MenuButtonTest, ActivateDropDownOnGestureTap) { |
| TEST_F(MenuButtonTest, TouchFeedbackDuringTap) { |
| TestMenuButtonListener menu_button_listener; |
| CreateMenuButtonWithMenuButtonListener(&menu_button_listener); |
| - ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); |
| - generator.set_current_location(gfx::Point(10, 10)); |
| - generator.PressTouch(); |
| + generator()->set_current_location(gfx::Point(10, 10)); |
| + generator()->PressTouch(); |
| EXPECT_EQ(Button::STATE_HOVERED, button()->state()); |
| - generator.ReleaseTouch(); |
| + generator()->ReleaseTouch(); |
| EXPECT_EQ(Button::STATE_HOVERED, menu_button_listener.last_source_state()); |
| } |
| @@ -491,13 +481,12 @@ TEST_F(MenuButtonTest, TouchFeedbackDuringTap) { |
| TEST_F(MenuButtonTest, TouchFeedbackDuringTapCancel) { |
| TestMenuButtonListener menu_button_listener; |
| CreateMenuButtonWithMenuButtonListener(&menu_button_listener); |
| - ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); |
| - generator.set_current_location(gfx::Point(10, 10)); |
| - generator.PressTouch(); |
| + generator()->set_current_location(gfx::Point(10, 10)); |
| + generator()->PressTouch(); |
| EXPECT_EQ(Button::STATE_HOVERED, button()->state()); |
| - generator.MoveTouch(gfx::Point(10, 30)); |
| - generator.ReleaseTouch(); |
| + generator()->MoveTouch(gfx::Point(10, 30)); |
| + generator()->ReleaseTouch(); |
| EXPECT_EQ(Button::STATE_NORMAL, button()->state()); |
| EXPECT_EQ(nullptr, menu_button_listener.last_source()); |
| } |