| 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 "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 widget_->SetContentsView(button_); | 124 widget_->SetContentsView(button_); |
| 125 } | 125 } |
| 126 | 126 |
| 127 protected: | 127 protected: |
| 128 Widget* widget() { return widget_.get(); } | 128 Widget* widget() { return widget_.get(); } |
| 129 TestCustomButton* button() { return button_; } | 129 TestCustomButton* button() { return button_; } |
| 130 void SetDraggedView(View* dragged_view) { | 130 void SetDraggedView(View* dragged_view) { |
| 131 widget_->dragged_view_ = dragged_view; | 131 widget_->dragged_view_ = dragged_view; |
| 132 } | 132 } |
| 133 | 133 |
| 134 void SimulateKeyEvent(ui::KeyEvent* event) { widget()->OnKeyEvent(event); } |
| 135 |
| 134 private: | 136 private: |
| 135 std::unique_ptr<Widget> widget_; | 137 std::unique_ptr<Widget> widget_; |
| 136 TestCustomButton* button_; | 138 TestCustomButton* button_; |
| 137 | 139 |
| 138 DISALLOW_COPY_AND_ASSIGN(CustomButtonTest); | 140 DISALLOW_COPY_AND_ASSIGN(CustomButtonTest); |
| 139 }; | 141 }; |
| 140 | 142 |
| 141 // Tests that hover state changes correctly when visiblity/enableness changes. | 143 // Tests that hover state changes correctly when visiblity/enableness changes. |
| 142 TEST_F(CustomButtonTest, HoverStateOnVisibilityChange) { | 144 TEST_F(CustomButtonTest, HoverStateOnVisibilityChange) { |
| 143 ui::test::EventGenerator generator(widget()->GetNativeWindow()); | 145 ui::test::EventGenerator generator(widget()->GetNativeWindow()); |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 | 517 |
| 516 button()->OnMouseDragged(ui::MouseEvent( | 518 button()->OnMouseDragged(ui::MouseEvent( |
| 517 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 519 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 518 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 520 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 519 | 521 |
| 520 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); | 522 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); |
| 521 | 523 |
| 522 SetDraggedView(nullptr); | 524 SetDraggedView(nullptr); |
| 523 } | 525 } |
| 524 | 526 |
| 527 // Todo(karandeepb): On Mac, a button should get clicked on a Space key press |
| 528 // (and not release). Modify this test after fixing crbug.com/607429. |
| 529 // Test that Space Key behaves correctly on a focused button. |
| 530 TEST_F(CustomButtonTest, ClickOnSpace) { |
| 531 // Give focus to the button. |
| 532 button()->SetFocusForPlatform(); |
| 533 button()->RequestFocus(); |
| 534 EXPECT_EQ(button(), widget()->GetFocusManager()->GetFocusedView()); |
| 535 |
| 536 ui::KeyEvent space_press(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, ui::EF_NONE); |
| 537 SimulateKeyEvent(&space_press); |
| 538 EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state()); |
| 539 EXPECT_FALSE(button()->pressed()); |
| 540 |
| 541 ui::KeyEvent space_release(ui::ET_KEY_RELEASED, ui::VKEY_SPACE, ui::EF_NONE); |
| 542 SimulateKeyEvent(&space_release); |
| 543 EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state()); |
| 544 EXPECT_TRUE(button()->pressed()); |
| 545 } |
| 546 |
| 525 } // namespace views | 547 } // namespace views |
| OLD | NEW |