Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(850)

Side by Side Diff: ui/views/controls/button/menu_button_unittest.cc

Issue 681753004: Standardize usage of virtual/override/final specifiers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/controls/button/menu_button.h ('k') | ui/views/controls/button/radio_button.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/base/dragdrop/drag_drop_types.h" 9 #include "ui/base/dragdrop/drag_drop_types.h"
10 #include "ui/events/test/event_generator.h" 10 #include "ui/events/test/event_generator.h"
11 #include "ui/views/controls/button/menu_button_listener.h" 11 #include "ui/views/controls/button/menu_button_listener.h"
12 #include "ui/views/drag_controller.h" 12 #include "ui/views/drag_controller.h"
13 #include "ui/views/test/views_test_base.h" 13 #include "ui/views/test/views_test_base.h"
14 14
15 #if defined(USE_AURA) 15 #if defined(USE_AURA)
16 #include "ui/events/event.h" 16 #include "ui/events/event.h"
17 #include "ui/events/event_handler.h" 17 #include "ui/events/event_handler.h"
18 #include "ui/wm/public/drag_drop_client.h" 18 #include "ui/wm/public/drag_drop_client.h"
19 #endif 19 #endif
20 20
21 using base::ASCIIToUTF16; 21 using base::ASCIIToUTF16;
22 22
23 namespace views { 23 namespace views {
24 24
25 class MenuButtonTest : public ViewsTestBase { 25 class MenuButtonTest : public ViewsTestBase {
26 public: 26 public:
27 MenuButtonTest() : widget_(nullptr), button_(nullptr) {} 27 MenuButtonTest() : widget_(nullptr), button_(nullptr) {}
28 virtual ~MenuButtonTest() {} 28 ~MenuButtonTest() override {}
29 29
30 void TearDown() override { 30 void TearDown() override {
31 if (widget_ && !widget_->IsClosed()) 31 if (widget_ && !widget_->IsClosed())
32 widget_->Close(); 32 widget_->Close();
33 33
34 ViewsTestBase::TearDown(); 34 ViewsTestBase::TearDown();
35 } 35 }
36 36
37 Widget* widget() { return widget_; } 37 Widget* widget() { return widget_; }
38 MenuButton* button() { return button_; } 38 MenuButton* button() { return button_; }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 Widget* widget_; 82 Widget* widget_;
83 MenuButton* button_; 83 MenuButton* button_;
84 }; 84 };
85 85
86 class TestButtonListener : public ButtonListener { 86 class TestButtonListener : public ButtonListener {
87 public: 87 public:
88 TestButtonListener() 88 TestButtonListener()
89 : last_sender_(nullptr), 89 : last_sender_(nullptr),
90 last_sender_state_(Button::STATE_NORMAL), 90 last_sender_state_(Button::STATE_NORMAL),
91 last_event_type_(ui::ET_UNKNOWN) {} 91 last_event_type_(ui::ET_UNKNOWN) {}
92 virtual ~TestButtonListener() {} 92 ~TestButtonListener() override {}
93 93
94 void ButtonPressed(Button* sender, const ui::Event& event) override { 94 void ButtonPressed(Button* sender, const ui::Event& event) override {
95 last_sender_ = sender; 95 last_sender_ = sender;
96 CustomButton* custom_button = CustomButton::AsCustomButton(sender); 96 CustomButton* custom_button = CustomButton::AsCustomButton(sender);
97 DCHECK(custom_button); 97 DCHECK(custom_button);
98 last_sender_state_ = custom_button->state(); 98 last_sender_state_ = custom_button->state();
99 last_event_type_ = event.type(); 99 last_event_type_ = event.type();
100 } 100 }
101 101
102 Button* last_sender() { return last_sender_; } 102 Button* last_sender() { return last_sender_; }
103 Button::ButtonState last_sender_state() { return last_sender_state_; } 103 Button::ButtonState last_sender_state() { return last_sender_state_; }
104 ui::EventType last_event_type() { return last_event_type_; } 104 ui::EventType last_event_type() { return last_event_type_; }
105 105
106 private: 106 private:
107 Button* last_sender_; 107 Button* last_sender_;
108 Button::ButtonState last_sender_state_; 108 Button::ButtonState last_sender_state_;
109 ui::EventType last_event_type_; 109 ui::EventType last_event_type_;
110 110
111 DISALLOW_COPY_AND_ASSIGN(TestButtonListener); 111 DISALLOW_COPY_AND_ASSIGN(TestButtonListener);
112 }; 112 };
113 113
114 class TestMenuButtonListener : public MenuButtonListener { 114 class TestMenuButtonListener : public MenuButtonListener {
115 public: 115 public:
116 TestMenuButtonListener() 116 TestMenuButtonListener()
117 : last_source_(nullptr), last_source_state_(Button::STATE_NORMAL) {} 117 : last_source_(nullptr), last_source_state_(Button::STATE_NORMAL) {}
118 virtual ~TestMenuButtonListener() {} 118 ~TestMenuButtonListener() override {}
119 119
120 void OnMenuButtonClicked(View* source, const gfx::Point& /*point*/) override { 120 void OnMenuButtonClicked(View* source, const gfx::Point& /*point*/) override {
121 last_source_ = source; 121 last_source_ = source;
122 CustomButton* custom_button = CustomButton::AsCustomButton(source); 122 CustomButton* custom_button = CustomButton::AsCustomButton(source);
123 DCHECK(custom_button); 123 DCHECK(custom_button);
124 last_source_state_ = custom_button->state(); 124 last_source_state_ = custom_button->state();
125 } 125 }
126 126
127 View* last_source() { return last_source_; } 127 View* last_source() { return last_source_; }
128 Button::ButtonState last_source_state() { return last_source_state_; } 128 Button::ButtonState last_source_state() { return last_source_state_; }
129 129
130 private: 130 private:
131 View* last_source_; 131 View* last_source_;
132 Button::ButtonState last_source_state_; 132 Button::ButtonState last_source_state_;
133 }; 133 };
134 134
135 // Basic implementation of a DragController, to test input behaviour for 135 // Basic implementation of a DragController, to test input behaviour for
136 // MenuButtons that can be dragged. 136 // MenuButtons that can be dragged.
137 class TestDragController : public DragController { 137 class TestDragController : public DragController {
138 public: 138 public:
139 TestDragController() {} 139 TestDragController() {}
140 virtual ~TestDragController() {} 140 ~TestDragController() override {}
141 141
142 void WriteDragDataForView(View* sender, 142 void WriteDragDataForView(View* sender,
143 const gfx::Point& press_pt, 143 const gfx::Point& press_pt,
144 ui::OSExchangeData* data) override {} 144 ui::OSExchangeData* data) override {}
145 145
146 int GetDragOperationsForView(View* sender, const gfx::Point& p) override { 146 int GetDragOperationsForView(View* sender, const gfx::Point& p) override {
147 return ui::DragDropTypes::DRAG_MOVE; 147 return ui::DragDropTypes::DRAG_MOVE;
148 } 148 }
149 149
150 bool CanStartDragForView(View* sender, 150 bool CanStartDragForView(View* sender,
151 const gfx::Point& press_pt, 151 const gfx::Point& press_pt,
152 const gfx::Point& p) override { 152 const gfx::Point& p) override {
153 return true; 153 return true;
154 } 154 }
155 155
156 private: 156 private:
157 DISALLOW_COPY_AND_ASSIGN(TestDragController); 157 DISALLOW_COPY_AND_ASSIGN(TestDragController);
158 }; 158 };
159 159
160 #if defined(USE_AURA) 160 #if defined(USE_AURA)
161 // Basic implementation of a DragDropClient, tracking the state of the drag 161 // Basic implementation of a DragDropClient, tracking the state of the drag
162 // operation. While dragging addition mouse events are consumed, preventing the 162 // operation. While dragging addition mouse events are consumed, preventing the
163 // target view from receiving them. 163 // target view from receiving them.
164 class TestDragDropClient : public aura::client::DragDropClient, 164 class TestDragDropClient : public aura::client::DragDropClient,
165 public ui::EventHandler { 165 public ui::EventHandler {
166 public: 166 public:
167 TestDragDropClient(); 167 TestDragDropClient();
168 virtual ~TestDragDropClient(); 168 ~TestDragDropClient() override;
169 169
170 // aura::client::DragDropClient: 170 // aura::client::DragDropClient:
171 int StartDragAndDrop(const ui::OSExchangeData& data, 171 int StartDragAndDrop(const ui::OSExchangeData& data,
172 aura::Window* root_window, 172 aura::Window* root_window,
173 aura::Window* source_window, 173 aura::Window* source_window,
174 const gfx::Point& root_location, 174 const gfx::Point& root_location,
175 int operation, 175 int operation,
176 ui::DragDropTypes::DragEventSource source) override; 176 ui::DragDropTypes::DragEventSource source) override;
177 void DragUpdate(aura::Window* target, const ui::LocatedEvent& event) override; 177 void DragUpdate(aura::Window* target, const ui::LocatedEvent& event) override;
178 void Drop(aura::Window* target, const ui::LocatedEvent& event) override; 178 void Drop(aura::Window* target, const ui::LocatedEvent& event) override;
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 384
385 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); 385 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow());
386 generator.set_current_location(gfx::Point(10, 10)); 386 generator.set_current_location(gfx::Point(10, 10));
387 generator.DragMouseBy(10, 0); 387 generator.DragMouseBy(10, 0);
388 EXPECT_EQ(nullptr, menu_button_listener.last_source()); 388 EXPECT_EQ(nullptr, menu_button_listener.last_source());
389 EXPECT_EQ(Button::STATE_NORMAL, menu_button_listener.last_source_state()); 389 EXPECT_EQ(Button::STATE_NORMAL, menu_button_listener.last_source_state());
390 } 390 }
391 #endif 391 #endif
392 392
393 } // namespace views 393 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/menu_button.h ('k') | ui/views/controls/button/radio_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698