| 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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/aura/test/event_generator.h" | |
| 9 #include "ui/aura/window.h" | |
| 10 #include "ui/views/controls/button/menu_button_listener.h" | 8 #include "ui/views/controls/button/menu_button_listener.h" |
| 11 #include "ui/views/test/views_test_base.h" | 9 #include "ui/views/test/views_test_base.h" |
| 10 #include "ui/views/test/widget_event_generator.h" |
| 12 | 11 |
| 13 using base::ASCIIToUTF16; | 12 using base::ASCIIToUTF16; |
| 14 | 13 |
| 15 namespace views { | 14 namespace views { |
| 16 | 15 |
| 17 class MenuButtonTest : public ViewsTestBase { | 16 class MenuButtonTest : public ViewsTestBase { |
| 18 public: | 17 public: |
| 19 MenuButtonTest() : widget_(NULL), button_(NULL) {} | 18 MenuButtonTest() : widget_(NULL), button_(NULL) {} |
| 20 virtual ~MenuButtonTest() {} | 19 virtual ~MenuButtonTest() {} |
| 21 | 20 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 View* last_source_; | 120 View* last_source_; |
| 122 Button::ButtonState last_source_state_; | 121 Button::ButtonState last_source_state_; |
| 123 }; | 122 }; |
| 124 | 123 |
| 125 // Tests if the listener is notified correctly, when a mouse click happens on a | 124 // Tests if the listener is notified correctly, when a mouse click happens on a |
| 126 // MenuButton that has a regular ButtonListener. | 125 // MenuButton that has a regular ButtonListener. |
| 127 TEST_F(MenuButtonTest, ActivateNonDropDownOnMouseClick) { | 126 TEST_F(MenuButtonTest, ActivateNonDropDownOnMouseClick) { |
| 128 scoped_ptr<TestButtonListener> button_listener(new TestButtonListener); | 127 scoped_ptr<TestButtonListener> button_listener(new TestButtonListener); |
| 129 CreateMenuButtonWithButtonListener(button_listener.get()); | 128 CreateMenuButtonWithButtonListener(button_listener.get()); |
| 130 | 129 |
| 131 aura::test::EventGenerator generator( | 130 test::WidgetEventGenerator generator(widget()); |
| 132 widget()->GetNativeView()->GetRootWindow()); | |
| 133 | 131 |
| 134 generator.set_current_location(gfx::Point(10, 10)); | 132 generator.set_current_location(gfx::Point(10, 10)); |
| 135 generator.ClickLeftButton(); | 133 generator.ClickLeftButton(); |
| 136 | 134 |
| 137 // Check that MenuButton has notified the listener on mouse-released event, | 135 // Check that MenuButton has notified the listener on mouse-released event, |
| 138 // while it was in hovered state. | 136 // while it was in hovered state. |
| 139 EXPECT_EQ(button(), button_listener->last_sender()); | 137 EXPECT_EQ(button(), button_listener->last_sender()); |
| 140 EXPECT_EQ(ui::ET_MOUSE_RELEASED, button_listener->last_event_type()); | 138 EXPECT_EQ(ui::ET_MOUSE_RELEASED, button_listener->last_event_type()); |
| 141 EXPECT_EQ(Button::STATE_HOVERED, button_listener->last_sender_state()); | 139 EXPECT_EQ(Button::STATE_HOVERED, button_listener->last_sender_state()); |
| 142 } | 140 } |
| 143 | 141 |
| 144 // Tests if the listener is notified correctly when a gesture tap happens on a | 142 // Tests if the listener is notified correctly when a gesture tap happens on a |
| 145 // MenuButton that has a regular ButtonListener. | 143 // MenuButton that has a regular ButtonListener. |
| 146 TEST_F(MenuButtonTest, ActivateNonDropDownOnGestureTap) { | 144 TEST_F(MenuButtonTest, ActivateNonDropDownOnGestureTap) { |
| 147 scoped_ptr<TestButtonListener> button_listener(new TestButtonListener); | 145 scoped_ptr<TestButtonListener> button_listener(new TestButtonListener); |
| 148 CreateMenuButtonWithButtonListener(button_listener.get()); | 146 CreateMenuButtonWithButtonListener(button_listener.get()); |
| 149 | 147 |
| 150 aura::test::EventGenerator generator( | 148 test::WidgetEventGenerator generator(widget()); |
| 151 widget()->GetNativeView()->GetRootWindow()); | |
| 152 | |
| 153 generator.GestureTapAt(gfx::Point(10, 10)); | 149 generator.GestureTapAt(gfx::Point(10, 10)); |
| 154 | 150 |
| 155 // Check that MenuButton has notified the listener on gesture tap event, while | 151 // Check that MenuButton has notified the listener on gesture tap event, while |
| 156 // it was in hovered state. | 152 // it was in hovered state. |
| 157 EXPECT_EQ(button(), button_listener->last_sender()); | 153 EXPECT_EQ(button(), button_listener->last_sender()); |
| 158 EXPECT_EQ(ui::ET_GESTURE_TAP, button_listener->last_event_type()); | 154 EXPECT_EQ(ui::ET_GESTURE_TAP, button_listener->last_event_type()); |
| 159 EXPECT_EQ(Button::STATE_HOVERED, button_listener->last_sender_state()); | 155 EXPECT_EQ(Button::STATE_HOVERED, button_listener->last_sender_state()); |
| 160 } | 156 } |
| 161 | 157 |
| 162 // Tests if the listener is notified correctly when a mouse click happens on a | 158 // Tests if the listener is notified correctly when a mouse click happens on a |
| 163 // MenuButton that has a MenuButtonListener. | 159 // MenuButton that has a MenuButtonListener. |
| 164 TEST_F(MenuButtonTest, ActivateDropDownOnMouseClick) { | 160 TEST_F(MenuButtonTest, ActivateDropDownOnMouseClick) { |
| 165 scoped_ptr<TestMenuButtonListener> menu_button_listener( | 161 scoped_ptr<TestMenuButtonListener> menu_button_listener( |
| 166 new TestMenuButtonListener); | 162 new TestMenuButtonListener); |
| 167 CreateMenuButtonWithMenuButtonListener(menu_button_listener.get()); | 163 CreateMenuButtonWithMenuButtonListener(menu_button_listener.get()); |
| 168 | 164 |
| 169 aura::test::EventGenerator generator( | 165 test::WidgetEventGenerator generator(widget()); |
| 170 widget()->GetNativeView()->GetRootWindow()); | |
| 171 | 166 |
| 172 generator.set_current_location(gfx::Point(10, 10)); | 167 generator.set_current_location(gfx::Point(10, 10)); |
| 173 generator.ClickLeftButton(); | 168 generator.ClickLeftButton(); |
| 174 | 169 |
| 175 // Check that MenuButton has notified the listener, while it was in pressed | 170 // Check that MenuButton has notified the listener, while it was in pressed |
| 176 // state. | 171 // state. |
| 177 EXPECT_EQ(button(), menu_button_listener->last_source()); | 172 EXPECT_EQ(button(), menu_button_listener->last_source()); |
| 178 EXPECT_EQ(Button::STATE_PRESSED, menu_button_listener->last_source_state()); | 173 EXPECT_EQ(Button::STATE_PRESSED, menu_button_listener->last_source_state()); |
| 179 } | 174 } |
| 180 | 175 |
| 181 // Tests if the listener is notified correctly when a gesture tap happens on a | 176 // Tests if the listener is notified correctly when a gesture tap happens on a |
| 182 // MenuButton that has a MenuButtonListener. | 177 // MenuButton that has a MenuButtonListener. |
| 183 TEST_F(MenuButtonTest, ActivateDropDownOnGestureTap) { | 178 TEST_F(MenuButtonTest, ActivateDropDownOnGestureTap) { |
| 184 scoped_ptr<TestMenuButtonListener> menu_button_listener( | 179 scoped_ptr<TestMenuButtonListener> menu_button_listener( |
| 185 new TestMenuButtonListener); | 180 new TestMenuButtonListener); |
| 186 CreateMenuButtonWithMenuButtonListener(menu_button_listener.get()); | 181 CreateMenuButtonWithMenuButtonListener(menu_button_listener.get()); |
| 187 | 182 |
| 188 aura::test::EventGenerator generator( | 183 test::WidgetEventGenerator generator(widget()); |
| 189 widget()->GetNativeView()->GetRootWindow()); | |
| 190 | |
| 191 generator.GestureTapAt(gfx::Point(10, 10)); | 184 generator.GestureTapAt(gfx::Point(10, 10)); |
| 192 | 185 |
| 193 // Check that MenuButton has notified the listener, while it was in pressed | 186 // Check that MenuButton has notified the listener, while it was in pressed |
| 194 // state. | 187 // state. |
| 195 EXPECT_EQ(button(), menu_button_listener->last_source()); | 188 EXPECT_EQ(button(), menu_button_listener->last_source()); |
| 196 EXPECT_EQ(Button::STATE_PRESSED, menu_button_listener->last_source_state()); | 189 EXPECT_EQ(Button::STATE_PRESSED, menu_button_listener->last_source_state()); |
| 197 } | 190 } |
| 198 | 191 |
| 199 } // namespace views | 192 } // namespace views |
| OLD | NEW |