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