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..db36927d7b500f81cd15e4d253678229cc97d614 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() : generator(nullptr), widget_(nullptr), button_(nullptr) {} |
tapted
2016/02/09 05:06:41
nit: doesn't need an initializer now that it's a s
Patti Lor
2016/02/12 04:42:20
Done.
|
~MenuButtonTest() override {} |
void TearDown() override { |
@@ -57,10 +57,14 @@ class MenuButtonTest : public ViewsTestBase { |
CreateMenuButton(nullptr, menu_button_listener); |
} |
+ scoped_ptr<ui::test::EventGenerator> generator; |
tapted
2016/02/09 05:06:41
generator -> generator_
also, this should go back
Patti Lor
2016/02/12 04:42:20
Having the generator scoped_ptr be private means I
tapted
2016/02/12 04:44:54
returning generator_.get() is fine for this kind o
|
+ |
private: |
void CreateMenuButton(ButtonListener* button_listener, |
MenuButtonListener* menu_button_listener) { |
CreateWidget(); |
+ generator = make_scoped_ptr(new ui::test::EventGenerator(GetContext(), |
tapted
2016/02/09 05:06:41
nit: make_scoped_ptr is used mostly after a `retur
Patti Lor
2016/02/12 04:42:20
Done.
|
+ widget_->GetNativeWindow())); |
const base::string16 label(ASCIIToUTF16("button")); |
button_ = |
@@ -83,6 +87,8 @@ class MenuButtonTest : public ViewsTestBase { |
Widget* widget_; |
MenuButton* button_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MenuButtonTest); |
}; |
class TestButtonListener : public ButtonListener { |
@@ -274,10 +280,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 +296,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 +310,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 +319,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 +336,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 +354,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 +372,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 +386,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 +409,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 +426,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 +449,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 +470,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 +483,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()); |
} |