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/command_line.h" |
7 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
9 #include "ui/base/dragdrop/drag_drop_types.h" | 10 #include "ui/base/dragdrop/drag_drop_types.h" |
| 11 #include "ui/base/ui_base_switches.h" |
10 #include "ui/events/test/event_generator.h" | 12 #include "ui/events/test/event_generator.h" |
11 #include "ui/views/controls/button/menu_button_listener.h" | 13 #include "ui/views/controls/button/menu_button_listener.h" |
12 #include "ui/views/drag_controller.h" | 14 #include "ui/views/drag_controller.h" |
13 #include "ui/views/test/views_test_base.h" | 15 #include "ui/views/test/views_test_base.h" |
14 | 16 |
15 #if defined(USE_AURA) | 17 #if defined(USE_AURA) |
16 #include "ui/events/event.h" | 18 #include "ui/events/event.h" |
17 #include "ui/events/event_handler.h" | 19 #include "ui/events/event_handler.h" |
18 #include "ui/wm/public/drag_drop_client.h" | 20 #include "ui/wm/public/drag_drop_client.h" |
19 #endif | 21 #endif |
20 | 22 |
21 using base::ASCIIToUTF16; | 23 using base::ASCIIToUTF16; |
22 | 24 |
23 namespace views { | 25 namespace views { |
24 | 26 |
25 class MenuButtonTest : public ViewsTestBase { | 27 class MenuButtonTest : public ViewsTestBase { |
26 public: | 28 public: |
27 MenuButtonTest() : widget_(nullptr), button_(nullptr) {} | 29 MenuButtonTest() : widget_(nullptr), button_(nullptr) {} |
28 virtual ~MenuButtonTest() {} | 30 virtual ~MenuButtonTest() {} |
29 | 31 |
| 32 void SetUp() override { |
| 33 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 34 switches::kEnableTouchFeedback); |
| 35 ViewsTestBase::SetUp(); |
| 36 } |
| 37 |
30 void TearDown() override { | 38 void TearDown() override { |
31 if (widget_ && !widget_->IsClosed()) | 39 if (widget_ && !widget_->IsClosed()) |
32 widget_->Close(); | 40 widget_->Close(); |
33 | 41 |
34 ViewsTestBase::TearDown(); | 42 ViewsTestBase::TearDown(); |
35 } | 43 } |
36 | 44 |
37 Widget* widget() { return widget_; } | 45 Widget* widget() { return widget_; } |
38 MenuButton* button() { return button_; } | 46 MenuButton* button() { return button_; } |
39 | 47 |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 button()->PrependPreTargetHandler(&drag_client); | 391 button()->PrependPreTargetHandler(&drag_client); |
384 | 392 |
385 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); | 393 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); |
386 generator.set_current_location(gfx::Point(10, 10)); | 394 generator.set_current_location(gfx::Point(10, 10)); |
387 generator.DragMouseBy(10, 0); | 395 generator.DragMouseBy(10, 0); |
388 EXPECT_EQ(nullptr, menu_button_listener.last_source()); | 396 EXPECT_EQ(nullptr, menu_button_listener.last_source()); |
389 EXPECT_EQ(Button::STATE_NORMAL, menu_button_listener.last_source_state()); | 397 EXPECT_EQ(Button::STATE_NORMAL, menu_button_listener.last_source_state()); |
390 } | 398 } |
391 #endif | 399 #endif |
392 | 400 |
| 401 // Tests that the button enters a hovered state upon a tap down, before becoming |
| 402 // pressed at activation. |
| 403 TEST_F(MenuButtonTest, TouchFeedbackDuringTap) { |
| 404 TestMenuButtonListener menu_button_listener; |
| 405 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); |
| 406 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); |
| 407 generator.set_current_location(gfx::Point(10, 10)); |
| 408 generator.PressTouch(); |
| 409 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); |
| 410 |
| 411 generator.ReleaseTouch(); |
| 412 EXPECT_EQ(Button::STATE_PRESSED, menu_button_listener.last_source_state()); |
| 413 } |
| 414 |
| 415 // Tests that a move event that exits the button returns it to the normal state, |
| 416 // and that the button did not activate the listener. |
| 417 TEST_F(MenuButtonTest, TouchFeedbackDuringTapCancel) { |
| 418 TestMenuButtonListener menu_button_listener; |
| 419 CreateMenuButtonWithMenuButtonListener(&menu_button_listener); |
| 420 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); |
| 421 generator.set_current_location(gfx::Point(10, 10)); |
| 422 generator.PressTouch(); |
| 423 EXPECT_EQ(Button::STATE_HOVERED, button()->state()); |
| 424 |
| 425 generator.MoveTouch(gfx::Point(10, 30)); |
| 426 generator.ReleaseTouch(); |
| 427 EXPECT_EQ(Button::STATE_NORMAL, button()->state()); |
| 428 EXPECT_EQ(nullptr, menu_button_listener.last_source()); |
| 429 } |
| 430 |
393 } // namespace views | 431 } // namespace views |
OLD | NEW |