| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 71 } |
| 72 | 72 |
| 73 bool pressed() { return pressed_; } | 73 bool pressed() { return pressed_; } |
| 74 bool canceled() { return canceled_; } | 74 bool canceled() { return canceled_; } |
| 75 | 75 |
| 76 void Reset() { | 76 void Reset() { |
| 77 pressed_ = false; | 77 pressed_ = false; |
| 78 canceled_ = false; | 78 canceled_ = false; |
| 79 } | 79 } |
| 80 | 80 |
| 81 private: | 81 // Raised visibility of OnFocus() to public |
| 82 void OnFocus() override { |
| 83 CustomButton::OnFocus(); |
| 84 } |
| 85 |
| 86 private: |
| 82 bool pressed_ = false; | 87 bool pressed_ = false; |
| 83 bool canceled_ = false; | 88 bool canceled_ = false; |
| 84 | 89 |
| 85 DISALLOW_COPY_AND_ASSIGN(TestCustomButton); | 90 DISALLOW_COPY_AND_ASSIGN(TestCustomButton); |
| 86 }; | 91 }; |
| 87 | 92 |
| 88 // An InkDropDelegate that keeps track of ink drop visibility. | 93 // An InkDropDelegate that keeps track of ink drop visibility. |
| 89 class TestInkDropDelegateThatTracksVisibilty : public TestInkDropDelegate { | 94 class TestInkDropDelegateThatTracksVisibilty : public TestInkDropDelegate { |
| 90 public: | 95 public: |
| 91 TestInkDropDelegateThatTracksVisibilty(bool* ink_shown, bool* ink_hidden) | 96 TestInkDropDelegateThatTracksVisibilty(bool* ink_shown, bool* ink_hidden) |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 ink_drop_delegate->SetHovered(true); | 466 ink_drop_delegate->SetHovered(true); |
| 462 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); | 467 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); |
| 463 | 468 |
| 464 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); | 469 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); |
| 465 | 470 |
| 466 EXPECT_TRUE(ink_drop_delegate->is_hovered()); | 471 EXPECT_TRUE(ink_drop_delegate->is_hovered()); |
| 467 EXPECT_EQ(InkDropState::ACTION_PENDING, | 472 EXPECT_EQ(InkDropState::ACTION_PENDING, |
| 468 ink_drop_delegate->GetTargetInkDropState()); | 473 ink_drop_delegate->GetTargetInkDropState()); |
| 469 } | 474 } |
| 470 | 475 |
| 476 TEST_F(CustomButtonTest, HideInkDropOnBlur) { |
| 477 gfx::Point center(10, 10); |
| 478 |
| 479 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); |
| 480 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate)); |
| 481 |
| 482 button()->OnFocus(); |
| 483 |
| 484 button()->OnMousePressed(ui::MouseEvent( |
| 485 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 486 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 487 EXPECT_EQ(InkDropState::ACTION_PENDING, |
| 488 ink_drop_delegate->GetTargetInkDropState()); |
| 489 |
| 490 button()->OnBlur(); |
| 491 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate->GetTargetInkDropState()); |
| 492 |
| 493 button()->OnMouseReleased(ui::MouseEvent( |
| 494 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 495 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 496 EXPECT_TRUE(button()->pressed()); |
| 497 } |
| 498 |
| 471 TEST_F(CustomButtonTest, InkDropAfterTryingToShowContextMenu) { | 499 TEST_F(CustomButtonTest, InkDropAfterTryingToShowContextMenu) { |
| 472 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); | 500 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); |
| 473 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate)); | 501 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate)); |
| 474 button()->set_context_menu_controller(nullptr); | 502 button()->set_context_menu_controller(nullptr); |
| 475 | 503 |
| 476 ink_drop_delegate->SetHovered(true); | 504 ink_drop_delegate->SetHovered(true); |
| 477 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); | 505 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); |
| 478 | 506 |
| 479 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); | 507 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); |
| 480 | 508 |
| 481 EXPECT_TRUE(ink_drop_delegate->is_hovered()); | 509 EXPECT_TRUE(ink_drop_delegate->is_hovered()); |
| 482 EXPECT_EQ(InkDropState::ACTION_PENDING, | 510 EXPECT_EQ(InkDropState::ACTION_PENDING, |
| 483 ink_drop_delegate->GetTargetInkDropState()); | 511 ink_drop_delegate->GetTargetInkDropState()); |
| 484 } | 512 } |
| 485 | 513 |
| 486 } // namespace views | 514 } // namespace views |
| OLD | NEW |