OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/custom_button.h" | 5 #include "ui/views/controls/button/custom_button.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/base/layout.h" | 8 #include "ui/base/layout.h" |
9 #include "ui/events/event_utils.h" | 9 #include "ui/events/event_utils.h" |
10 #include "ui/gfx/screen.h" | 10 #include "ui/gfx/screen.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 | 197 |
198 // The button should no longer notify on mouse release. | 198 // The button should no longer notify on mouse release. |
199 button()->Reset(); | 199 button()->Reset(); |
200 button()->OnMouseReleased(ui::MouseEvent( | 200 button()->OnMouseReleased(ui::MouseEvent( |
201 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), | 201 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), |
202 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 202 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
203 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state()); | 203 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state()); |
204 EXPECT_FALSE(button()->notified()); | 204 EXPECT_FALSE(button()->notified()); |
205 } | 205 } |
206 | 206 |
207 TEST_F(CustomButtonTest, HandleAcceleratorWhenFocused) { | |
208 // Shouldn't handle accelerators when not focused. | |
msw
2015/11/10 22:48:34
Update the test for the behavior I explained in my
meacer
2015/11/11 00:32:59
Added TestWidget class here.
| |
209 button()->GetFocusManager()->ClearFocus(); | |
210 button()->AcceleratorPressed(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); | |
211 EXPECT_FALSE(button()->notified()); | |
212 // Should handle accelerators when focused. | |
213 button()->GetFocusManager()->SetFocusedView(button()); | |
214 button()->AcceleratorPressed(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); | |
215 EXPECT_TRUE(button()->notified()); | |
216 // Focus lost again. | |
217 button()->Reset(); | |
218 button()->GetFocusManager()->ClearFocus(); | |
219 button()->AcceleratorPressed(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); | |
220 EXPECT_FALSE(button()->notified()); | |
221 } | |
222 | |
207 // No touch on desktop Mac. Tracked in http://crbug.com/445520. | 223 // No touch on desktop Mac. Tracked in http://crbug.com/445520. |
208 #if !defined(OS_MACOSX) || defined(USE_AURA) | 224 #if !defined(OS_MACOSX) || defined(USE_AURA) |
209 | 225 |
210 namespace { | 226 namespace { |
211 | 227 |
212 void PerformGesture(CustomButton* button, ui::EventType event_type) { | 228 void PerformGesture(CustomButton* button, ui::EventType event_type) { |
213 ui::GestureEventDetails gesture_details(event_type); | 229 ui::GestureEventDetails gesture_details(event_type); |
214 base::TimeDelta time_stamp = base::TimeDelta::FromMicroseconds(0); | 230 base::TimeDelta time_stamp = base::TimeDelta::FromMicroseconds(0); |
215 ui::GestureEvent gesture_event(0, 0, 0, time_stamp, gesture_details); | 231 ui::GestureEvent gesture_event(0, 0, 0, time_stamp, gesture_details); |
216 button->OnGestureEvent(&gesture_event); | 232 button->OnGestureEvent(&gesture_event); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 EXPECT_FALSE(CustomButton::AsCustomButton(&label)); | 276 EXPECT_FALSE(CustomButton::AsCustomButton(&label)); |
261 | 277 |
262 Link link(text); | 278 Link link(text); |
263 EXPECT_FALSE(CustomButton::AsCustomButton(&link)); | 279 EXPECT_FALSE(CustomButton::AsCustomButton(&link)); |
264 | 280 |
265 Textfield textfield; | 281 Textfield textfield; |
266 EXPECT_FALSE(CustomButton::AsCustomButton(&textfield)); | 282 EXPECT_FALSE(CustomButton::AsCustomButton(&textfield)); |
267 } | 283 } |
268 | 284 |
269 } // namespace views | 285 } // namespace views |
OLD | NEW |