Chromium Code Reviews| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 | 87 |
| 88 // An InkDropDelegate that keeps track of ink drop visibility. | 88 // An InkDropDelegate that keeps track of ink drop visibility. |
| 89 class TestInkDropDelegateThatTracksVisibilty : public InkDropDelegate { | 89 class TestInkDropDelegateThatTracksVisibilty : public InkDropDelegate { |
| 90 public: | 90 public: |
| 91 TestInkDropDelegateThatTracksVisibilty(bool* ink_shown, bool* ink_hidden) | 91 TestInkDropDelegateThatTracksVisibilty(bool* ink_shown, bool* ink_hidden) |
| 92 : ink_shown_(ink_shown), ink_hidden_(ink_hidden) {} | 92 : ink_shown_(ink_shown), ink_hidden_(ink_hidden) {} |
| 93 ~TestInkDropDelegateThatTracksVisibilty() override {} | 93 ~TestInkDropDelegateThatTracksVisibilty() override {} |
| 94 | 94 |
| 95 // InkDropDelegate: | 95 // InkDropDelegate: |
| 96 void OnAction(InkDropState state) override { | 96 void OnAction(InkDropState state) override { |
| 97 switch (state) { | 97 state_ = state; |
| 98 switch (state_) { | |
| 98 case InkDropState::ACTION_PENDING: | 99 case InkDropState::ACTION_PENDING: |
| 99 case InkDropState::ALTERNATE_ACTION_PENDING: | 100 case InkDropState::ALTERNATE_ACTION_PENDING: |
| 100 case InkDropState::ACTIVATED: | 101 case InkDropState::ACTIVATED: |
| 101 *ink_shown_ = true; | 102 *ink_shown_ = true; |
| 102 break; | 103 break; |
| 103 case InkDropState::HIDDEN: | 104 case InkDropState::HIDDEN: |
| 104 *ink_hidden_ = true; | 105 *ink_hidden_ = true; |
| 105 break; | 106 break; |
| 106 case InkDropState::ACTION_TRIGGERED: | 107 case InkDropState::ACTION_TRIGGERED: |
| 107 case InkDropState::ALTERNATE_ACTION_TRIGGERED: | 108 case InkDropState::ALTERNATE_ACTION_TRIGGERED: |
| 108 case InkDropState::DEACTIVATED: | 109 case InkDropState::DEACTIVATED: |
| 109 break; | 110 break; |
| 110 } | 111 } |
| 111 } | 112 } |
| 112 | 113 |
| 113 void SnapToActivated() override { *ink_shown_ = true; } | 114 void SnapToActivated() override { *ink_shown_ = true; } |
| 114 | 115 |
| 115 void SetHovered(bool is_hovered) override {} | 116 void SetHovered(bool is_hovered) override {} |
| 116 | 117 |
| 118 InkDropState GetTargetInkDropState() const override { return state_; } | |
|
bruthig
2016/05/14 00:17:24
Can you update TestInkDropDelegateThatTracksVisibi
| |
| 119 | |
| 117 private: | 120 private: |
| 118 bool* ink_shown_; | 121 bool* ink_shown_; |
| 119 bool* ink_hidden_; | 122 bool* ink_hidden_; |
| 123 InkDropState state_; | |
| 120 | 124 |
| 121 DISALLOW_COPY_AND_ASSIGN(TestInkDropDelegateThatTracksVisibilty); | 125 DISALLOW_COPY_AND_ASSIGN(TestInkDropDelegateThatTracksVisibilty); |
| 122 }; | 126 }; |
| 123 | 127 |
| 124 // A test Button class that owns a TestInkDropDelegate. | 128 // A test Button class that owns a TestInkDropDelegate. |
| 125 class TestButtonWithInkDrop : public TestCustomButton { | 129 class TestButtonWithInkDrop : public TestCustomButton { |
| 126 public: | 130 public: |
| 127 TestButtonWithInkDrop(std::unique_ptr<InkDropDelegate> ink_drop_delegate) | 131 TestButtonWithInkDrop(std::unique_ptr<InkDropDelegate> ink_drop_delegate) |
| 128 : TestCustomButton(), ink_drop_delegate_(std::move(ink_drop_delegate)) { | 132 : TestCustomButton(), ink_drop_delegate_(std::move(ink_drop_delegate)) { |
| 129 set_ink_drop_delegate(ink_drop_delegate_.get()); | 133 set_ink_drop_delegate(ink_drop_delegate_.get()); |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 TestContextMenuController context_menu_controller; | 445 TestContextMenuController context_menu_controller; |
| 442 button()->set_context_menu_controller(&context_menu_controller); | 446 button()->set_context_menu_controller(&context_menu_controller); |
| 443 button()->set_hide_ink_drop_when_showing_context_menu(true); | 447 button()->set_hide_ink_drop_when_showing_context_menu(true); |
| 444 | 448 |
| 445 ink_drop_delegate->SetHovered(true); | 449 ink_drop_delegate->SetHovered(true); |
| 446 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); | 450 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); |
| 447 | 451 |
| 448 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); | 452 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); |
| 449 | 453 |
| 450 EXPECT_FALSE(ink_drop_delegate->is_hovered()); | 454 EXPECT_FALSE(ink_drop_delegate->is_hovered()); |
| 451 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate->state()); | 455 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate->GetTargetInkDropState()); |
| 452 } | 456 } |
| 453 | 457 |
| 454 TEST_F(CustomButtonTest, DontHideInkDropWhenShowingContextMenu) { | 458 TEST_F(CustomButtonTest, DontHideInkDropWhenShowingContextMenu) { |
| 455 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); | 459 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); |
| 456 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate)); | 460 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate)); |
| 457 TestContextMenuController context_menu_controller; | 461 TestContextMenuController context_menu_controller; |
| 458 button()->set_context_menu_controller(&context_menu_controller); | 462 button()->set_context_menu_controller(&context_menu_controller); |
| 459 button()->set_hide_ink_drop_when_showing_context_menu(false); | 463 button()->set_hide_ink_drop_when_showing_context_menu(false); |
| 460 | 464 |
| 461 ink_drop_delegate->SetHovered(true); | 465 ink_drop_delegate->SetHovered(true); |
| 462 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); | 466 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); |
| 463 | 467 |
| 464 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); | 468 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); |
| 465 | 469 |
| 466 EXPECT_TRUE(ink_drop_delegate->is_hovered()); | 470 EXPECT_TRUE(ink_drop_delegate->is_hovered()); |
| 467 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop_delegate->state()); | 471 EXPECT_EQ(InkDropState::ACTION_PENDING, |
| 472 ink_drop_delegate->GetTargetInkDropState()); | |
| 468 } | 473 } |
| 469 | 474 |
| 470 TEST_F(CustomButtonTest, InkDropAfterTryingToShowContextMenu) { | 475 TEST_F(CustomButtonTest, InkDropAfterTryingToShowContextMenu) { |
| 471 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); | 476 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); |
| 472 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate)); | 477 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate)); |
| 473 button()->set_context_menu_controller(nullptr); | 478 button()->set_context_menu_controller(nullptr); |
| 474 | 479 |
| 475 ink_drop_delegate->SetHovered(true); | 480 ink_drop_delegate->SetHovered(true); |
| 476 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); | 481 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); |
| 477 | 482 |
| 478 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); | 483 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); |
| 479 | 484 |
| 480 EXPECT_TRUE(ink_drop_delegate->is_hovered()); | 485 EXPECT_TRUE(ink_drop_delegate->is_hovered()); |
| 481 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop_delegate->state()); | 486 EXPECT_EQ(InkDropState::ACTION_PENDING, |
| 487 ink_drop_delegate->GetTargetInkDropState()); | |
| 482 } | 488 } |
| 483 | 489 |
| 484 } // namespace views | 490 } // namespace views |
| OLD | NEW |