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/events/test/event_generator.h" | 9 #include "ui/events/test/event_generator.h" |
10 #include "ui/views/controls/button/menu_button_listener.h" | 10 #include "ui/views/controls/button/menu_button_listener.h" |
11 #include "ui/views/test/views_test_base.h" | 11 #include "ui/views/test/views_test_base.h" |
12 | 12 |
13 using base::ASCIIToUTF16; | 13 using base::ASCIIToUTF16; |
14 | 14 |
15 namespace views { | 15 namespace views { |
16 | 16 |
17 class MenuButtonTest : public ViewsTestBase { | 17 class MenuButtonTest : public ViewsTestBase { |
18 public: | 18 public: |
19 MenuButtonTest() : widget_(NULL), button_(NULL) {} | 19 MenuButtonTest() : widget_(NULL), button_(NULL) {} |
20 virtual ~MenuButtonTest() {} | 20 virtual ~MenuButtonTest() {} |
21 | 21 |
22 virtual void TearDown() OVERRIDE { | 22 virtual void TearDown() override { |
23 if (widget_ && !widget_->IsClosed()) | 23 if (widget_ && !widget_->IsClosed()) |
24 widget_->Close(); | 24 widget_->Close(); |
25 | 25 |
26 ViewsTestBase::TearDown(); | 26 ViewsTestBase::TearDown(); |
27 } | 27 } |
28 | 28 |
29 Widget* widget() { return widget_; } | 29 Widget* widget() { return widget_; } |
30 MenuButton* button() { return button_; } | 30 MenuButton* button() { return button_; } |
31 | 31 |
32 protected: | 32 protected: |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 }; | 78 }; |
79 | 79 |
80 class TestButtonListener : public ButtonListener { | 80 class TestButtonListener : public ButtonListener { |
81 public: | 81 public: |
82 TestButtonListener() | 82 TestButtonListener() |
83 : last_sender_(NULL), | 83 : last_sender_(NULL), |
84 last_sender_state_(Button::STATE_NORMAL), | 84 last_sender_state_(Button::STATE_NORMAL), |
85 last_event_type_(ui::ET_UNKNOWN) {} | 85 last_event_type_(ui::ET_UNKNOWN) {} |
86 virtual ~TestButtonListener() {} | 86 virtual ~TestButtonListener() {} |
87 | 87 |
88 virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE { | 88 virtual void ButtonPressed(Button* sender, const ui::Event& event) override { |
89 last_sender_ = sender; | 89 last_sender_ = sender; |
90 CustomButton* custom_button = CustomButton::AsCustomButton(sender); | 90 CustomButton* custom_button = CustomButton::AsCustomButton(sender); |
91 DCHECK(custom_button); | 91 DCHECK(custom_button); |
92 last_sender_state_ = custom_button->state(); | 92 last_sender_state_ = custom_button->state(); |
93 last_event_type_ = event.type(); | 93 last_event_type_ = event.type(); |
94 } | 94 } |
95 | 95 |
96 Button* last_sender() { return last_sender_; } | 96 Button* last_sender() { return last_sender_; } |
97 Button::ButtonState last_sender_state() { return last_sender_state_; } | 97 Button::ButtonState last_sender_state() { return last_sender_state_; } |
98 ui::EventType last_event_type() { return last_event_type_; } | 98 ui::EventType last_event_type() { return last_event_type_; } |
99 | 99 |
100 private: | 100 private: |
101 Button* last_sender_; | 101 Button* last_sender_; |
102 Button::ButtonState last_sender_state_; | 102 Button::ButtonState last_sender_state_; |
103 ui::EventType last_event_type_; | 103 ui::EventType last_event_type_; |
104 | 104 |
105 DISALLOW_COPY_AND_ASSIGN(TestButtonListener); | 105 DISALLOW_COPY_AND_ASSIGN(TestButtonListener); |
106 }; | 106 }; |
107 | 107 |
108 class TestMenuButtonListener : public MenuButtonListener { | 108 class TestMenuButtonListener : public MenuButtonListener { |
109 public: | 109 public: |
110 TestMenuButtonListener() {} | 110 TestMenuButtonListener() {} |
111 virtual ~TestMenuButtonListener() {} | 111 virtual ~TestMenuButtonListener() {} |
112 | 112 |
113 virtual void OnMenuButtonClicked(View* source, | 113 virtual void OnMenuButtonClicked(View* source, |
114 const gfx::Point& /*point*/) OVERRIDE { | 114 const gfx::Point& /*point*/) override { |
115 last_source_ = source; | 115 last_source_ = source; |
116 CustomButton* custom_button = CustomButton::AsCustomButton(source); | 116 CustomButton* custom_button = CustomButton::AsCustomButton(source); |
117 DCHECK(custom_button); | 117 DCHECK(custom_button); |
118 last_source_state_ = custom_button->state(); | 118 last_source_state_ = custom_button->state(); |
119 } | 119 } |
120 | 120 |
121 View* last_source() { return last_source_; } | 121 View* last_source() { return last_source_; } |
122 Button::ButtonState last_source_state() { return last_source_state_; } | 122 Button::ButtonState last_source_state() { return last_source_state_; } |
123 | 123 |
124 private: | 124 private: |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // Reseting the final lock should return the button's state to normal... | 224 // Reseting the final lock should return the button's state to normal... |
225 pressed_lock2.reset(); | 225 pressed_lock2.reset(); |
226 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); | 226 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); |
227 | 227 |
228 // ...And it should respond to mouse movement again. | 228 // ...And it should respond to mouse movement again. |
229 generator.MoveMouseTo(gfx::Point(10, 10)); | 229 generator.MoveMouseTo(gfx::Point(10, 10)); |
230 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); | 230 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); |
231 } | 231 } |
232 | 232 |
233 } // namespace views | 233 } // namespace views |
OLD | NEW |