| 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" |
| 11 #include "ui/base/layout.h" | 11 #include "ui/base/layout.h" |
| 12 #include "ui/base/material_design/material_design_controller.h" | 12 #include "ui/base/material_design/material_design_controller.h" |
| 13 #include "ui/display/screen.h" | 13 #include "ui/display/screen.h" |
| 14 #include "ui/events/event_utils.h" | 14 #include "ui/events/event_utils.h" |
| 15 #include "ui/events/test/event_generator.h" | 15 #include "ui/events/test/event_generator.h" |
| 16 #include "ui/views/animation/ink_drop_delegate.h" | |
| 17 #include "ui/views/animation/ink_drop_host.h" | 16 #include "ui/views/animation/ink_drop_host.h" |
| 18 #include "ui/views/animation/test/test_ink_drop_delegate.h" | 17 #include "ui/views/animation/test/ink_drop_host_view_test_api.h" |
| 18 #include "ui/views/animation/test/test_ink_drop.h" |
| 19 #include "ui/views/animation/test/test_ink_drop_host.h" | 19 #include "ui/views/animation/test/test_ink_drop_host.h" |
| 20 #include "ui/views/context_menu_controller.h" | 20 #include "ui/views/context_menu_controller.h" |
| 21 #include "ui/views/controls/button/checkbox.h" | 21 #include "ui/views/controls/button/checkbox.h" |
| 22 #include "ui/views/controls/button/image_button.h" | 22 #include "ui/views/controls/button/image_button.h" |
| 23 #include "ui/views/controls/button/label_button.h" | 23 #include "ui/views/controls/button/label_button.h" |
| 24 #include "ui/views/controls/button/menu_button.h" | 24 #include "ui/views/controls/button/menu_button.h" |
| 25 #include "ui/views/controls/button/radio_button.h" | 25 #include "ui/views/controls/button/radio_button.h" |
| 26 #include "ui/views/controls/link.h" | 26 #include "ui/views/controls/link.h" |
| 27 #include "ui/views/controls/textfield/textfield.h" | 27 #include "ui/views/controls/textfield/textfield.h" |
| 28 #include "ui/views/test/views_test_base.h" | 28 #include "ui/views/test/views_test_base.h" |
| 29 | 29 |
| 30 #if defined(USE_AURA) | 30 #if defined(USE_AURA) |
| 31 #include "ui/aura/test/test_cursor_client.h" | 31 #include "ui/aura/test/test_cursor_client.h" |
| 32 #include "ui/aura/window.h" | 32 #include "ui/aura/window.h" |
| 33 #include "ui/aura/window_event_dispatcher.h" | 33 #include "ui/aura/window_event_dispatcher.h" |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 namespace views { | 36 namespace views { |
| 37 | 37 |
| 38 using test::TestInkDropDelegate; | 38 using test::InkDropHostViewTestApi; |
| 39 using test::TestInkDrop; |
| 39 | 40 |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 // No-op test double of a ContextMenuController. | 43 // No-op test double of a ContextMenuController. |
| 43 class TestContextMenuController : public ContextMenuController { | 44 class TestContextMenuController : public ContextMenuController { |
| 44 public: | 45 public: |
| 45 TestContextMenuController() {} | 46 TestContextMenuController() {} |
| 46 ~TestContextMenuController() override {} | 47 ~TestContextMenuController() override {} |
| 47 | 48 |
| 48 // ContextMenuController: | 49 // ContextMenuController: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // Raised visibility of OnFocus() to public | 82 // Raised visibility of OnFocus() to public |
| 82 void OnFocus() override { CustomButton::OnFocus(); } | 83 void OnFocus() override { CustomButton::OnFocus(); } |
| 83 | 84 |
| 84 private: | 85 private: |
| 85 bool pressed_ = false; | 86 bool pressed_ = false; |
| 86 bool canceled_ = false; | 87 bool canceled_ = false; |
| 87 | 88 |
| 88 DISALLOW_COPY_AND_ASSIGN(TestCustomButton); | 89 DISALLOW_COPY_AND_ASSIGN(TestCustomButton); |
| 89 }; | 90 }; |
| 90 | 91 |
| 91 // An InkDropDelegate that keeps track of ink drop visibility. | |
| 92 class TestInkDropDelegateThatTracksVisibilty : public TestInkDropDelegate { | |
| 93 public: | |
| 94 TestInkDropDelegateThatTracksVisibilty(bool* ink_shown, bool* ink_hidden) | |
| 95 : ink_shown_(ink_shown), ink_hidden_(ink_hidden) {} | |
| 96 ~TestInkDropDelegateThatTracksVisibilty() override {} | |
| 97 | |
| 98 // InkDropDelegate: | |
| 99 void OnAction(InkDropState state) override { | |
| 100 TestInkDropDelegate::OnAction(state); | |
| 101 switch (GetTargetInkDropState()) { | |
| 102 case InkDropState::ACTION_PENDING: | |
| 103 case InkDropState::ALTERNATE_ACTION_PENDING: | |
| 104 case InkDropState::ACTIVATED: | |
| 105 *ink_shown_ = true; | |
| 106 break; | |
| 107 case InkDropState::HIDDEN: | |
| 108 *ink_hidden_ = true; | |
| 109 break; | |
| 110 case InkDropState::ACTION_TRIGGERED: | |
| 111 case InkDropState::ALTERNATE_ACTION_TRIGGERED: | |
| 112 case InkDropState::DEACTIVATED: | |
| 113 break; | |
| 114 } | |
| 115 } | |
| 116 | |
| 117 void SnapToActivated() override { *ink_shown_ = true; } | |
| 118 | |
| 119 void SetHovered(bool is_hovered) override {} | |
| 120 InkDrop* GetInkDrop() override { return nullptr; } | |
| 121 | |
| 122 private: | |
| 123 bool* ink_shown_; | |
| 124 bool* ink_hidden_; | |
| 125 | |
| 126 DISALLOW_COPY_AND_ASSIGN(TestInkDropDelegateThatTracksVisibilty); | |
| 127 }; | |
| 128 | |
| 129 // A test Button class that owns a TestInkDropDelegate. | |
| 130 class TestButtonWithInkDrop : public TestCustomButton { | |
| 131 public: | |
| 132 TestButtonWithInkDrop(std::unique_ptr<InkDropDelegate> ink_drop_delegate) | |
| 133 : TestCustomButton() { | |
| 134 set_ink_drop_delegate(std::move(ink_drop_delegate)); | |
| 135 } | |
| 136 ~TestButtonWithInkDrop() override {} | |
| 137 | |
| 138 private: | |
| 139 DISALLOW_COPY_AND_ASSIGN(TestButtonWithInkDrop); | |
| 140 }; | |
| 141 | |
| 142 } // namespace | 92 } // namespace |
| 143 | 93 |
| 144 class CustomButtonTest : public ViewsTestBase { | 94 class CustomButtonTest : public ViewsTestBase { |
| 145 public: | 95 public: |
| 146 CustomButtonTest() {} | 96 CustomButtonTest() {} |
| 147 ~CustomButtonTest() override {} | 97 ~CustomButtonTest() override {} |
| 148 | 98 |
| 149 void SetUp() override { | 99 void SetUp() override { |
| 150 ViewsTestBase::SetUp(); | 100 ViewsTestBase::SetUp(); |
| 151 | 101 |
| 152 // Create a widget so that the CustomButton can query the hover state | 102 // Create a widget so that the CustomButton can query the hover state |
| 153 // correctly. | 103 // correctly. |
| 154 widget_.reset(new Widget); | 104 widget_.reset(new Widget); |
| 155 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 105 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 156 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 106 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 157 params.bounds = gfx::Rect(0, 0, 650, 650); | 107 params.bounds = gfx::Rect(0, 0, 650, 650); |
| 158 widget_->Init(params); | 108 widget_->Init(params); |
| 159 widget_->Show(); | 109 widget_->Show(); |
| 160 | 110 |
| 161 button_ = new TestCustomButton(); | 111 button_ = new TestCustomButton(); |
| 162 widget_->SetContentsView(button_); | 112 widget_->SetContentsView(button_); |
| 163 } | 113 } |
| 164 | 114 |
| 165 void TearDown() override { | 115 void TearDown() override { |
| 166 widget_.reset(); | 116 widget_.reset(); |
| 167 ViewsTestBase::TearDown(); | 117 ViewsTestBase::TearDown(); |
| 168 } | 118 } |
| 169 | 119 |
| 170 void CreateButtonWithInkDrop( | 120 void CreateButtonWithInkDrop(std::unique_ptr<InkDrop> ink_drop) { |
| 171 std::unique_ptr<InkDropDelegate> ink_drop_delegate) { | |
| 172 delete button_; | 121 delete button_; |
| 173 button_ = new TestButtonWithInkDrop(std::move(ink_drop_delegate)); | 122 button_ = new TestCustomButton(); |
| 123 InkDropHostViewTestApi(button_).SetInkDrop(std::move(ink_drop)); |
| 174 widget_->SetContentsView(button_); | 124 widget_->SetContentsView(button_); |
| 175 } | 125 } |
| 176 | 126 |
| 177 protected: | 127 protected: |
| 178 Widget* widget() { return widget_.get(); } | 128 Widget* widget() { return widget_.get(); } |
| 179 TestCustomButton* button() { return button_; } | 129 TestCustomButton* button() { return button_; } |
| 180 void SetDraggedView(View* dragged_view) { | 130 void SetDraggedView(View* dragged_view) { |
| 181 widget_->dragged_view_ = dragged_view; | 131 widget_->dragged_view_ = dragged_view; |
| 182 } | 132 } |
| 183 | 133 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 Textfield textfield; | 339 Textfield textfield; |
| 390 EXPECT_FALSE(CustomButton::AsCustomButton(&textfield)); | 340 EXPECT_FALSE(CustomButton::AsCustomButton(&textfield)); |
| 391 } | 341 } |
| 392 | 342 |
| 393 // Tests that pressing a button shows the ink drop and releasing the button | 343 // Tests that pressing a button shows the ink drop and releasing the button |
| 394 // does not hide the ink drop. | 344 // does not hide the ink drop. |
| 395 // Note: Ink drop is not hidden upon release because CustomButton descendants | 345 // Note: Ink drop is not hidden upon release because CustomButton descendants |
| 396 // may enter a different ink drop state. | 346 // may enter a different ink drop state. |
| 397 TEST_F(CustomButtonTest, ButtonClickTogglesInkDrop) { | 347 TEST_F(CustomButtonTest, ButtonClickTogglesInkDrop) { |
| 398 gfx::Point old_cursor = display::Screen::GetScreen()->GetCursorScreenPoint(); | 348 gfx::Point old_cursor = display::Screen::GetScreen()->GetCursorScreenPoint(); |
| 399 bool ink_shown = false; | 349 TestInkDrop* ink_drop = new TestInkDrop(); |
| 400 bool ink_hidden = false; | 350 CreateButtonWithInkDrop(base::WrapUnique(ink_drop)); |
| 401 CreateButtonWithInkDrop(base::WrapUnique( | |
| 402 new TestInkDropDelegateThatTracksVisibilty(&ink_shown, &ink_hidden))); | |
| 403 | 351 |
| 404 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); | 352 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); |
| 405 generator.set_current_location(gfx::Point(50, 50)); | 353 generator.set_current_location(gfx::Point(50, 50)); |
| 406 generator.PressLeftButton(); | 354 generator.PressLeftButton(); |
| 407 EXPECT_TRUE(ink_shown); | 355 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); |
| 408 EXPECT_FALSE(ink_hidden); | |
| 409 | 356 |
| 410 generator.ReleaseLeftButton(); | 357 generator.ReleaseLeftButton(); |
| 411 EXPECT_FALSE(ink_hidden); | 358 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); |
| 412 } | 359 } |
| 413 | 360 |
| 414 // Tests that pressing a button shows and releasing capture hides ink drop. | 361 // Tests that pressing a button shows and releasing capture hides ink drop. |
| 415 // Releasing capture should also reset PRESSED button state to NORMAL. | 362 // Releasing capture should also reset PRESSED button state to NORMAL. |
| 416 TEST_F(CustomButtonTest, CaptureLossHidesInkDrop) { | 363 TEST_F(CustomButtonTest, CaptureLossHidesInkDrop) { |
| 417 gfx::Point old_cursor = display::Screen::GetScreen()->GetCursorScreenPoint(); | 364 gfx::Point old_cursor = display::Screen::GetScreen()->GetCursorScreenPoint(); |
| 418 bool ink_shown = false; | 365 TestInkDrop* ink_drop = new TestInkDrop(); |
| 419 bool ink_hidden = false; | 366 CreateButtonWithInkDrop(base::WrapUnique(ink_drop)); |
| 420 CreateButtonWithInkDrop(base::WrapUnique( | |
| 421 new TestInkDropDelegateThatTracksVisibilty(&ink_shown, &ink_hidden))); | |
| 422 | 367 |
| 423 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); | 368 ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); |
| 424 generator.set_current_location(gfx::Point(50, 50)); | 369 generator.set_current_location(gfx::Point(50, 50)); |
| 425 generator.PressLeftButton(); | 370 generator.PressLeftButton(); |
| 426 EXPECT_TRUE(ink_shown); | 371 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); |
| 427 EXPECT_FALSE(ink_hidden); | |
| 428 | 372 |
| 429 EXPECT_EQ(Button::ButtonState::STATE_PRESSED, button()->state()); | 373 EXPECT_EQ(Button::ButtonState::STATE_PRESSED, button()->state()); |
| 430 SetDraggedView(button()); | 374 SetDraggedView(button()); |
| 431 widget()->SetCapture(button()); | 375 widget()->SetCapture(button()); |
| 432 widget()->ReleaseCapture(); | 376 widget()->ReleaseCapture(); |
| 433 SetDraggedView(nullptr); | 377 SetDraggedView(nullptr); |
| 434 EXPECT_TRUE(ink_hidden); | 378 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); |
| 435 EXPECT_EQ(ui::MaterialDesignController::IsModeMaterial() | 379 EXPECT_EQ(ui::MaterialDesignController::IsModeMaterial() |
| 436 ? Button::ButtonState::STATE_NORMAL | 380 ? Button::ButtonState::STATE_NORMAL |
| 437 : Button::ButtonState::STATE_PRESSED, | 381 : Button::ButtonState::STATE_PRESSED, |
| 438 button()->state()); | 382 button()->state()); |
| 439 } | 383 } |
| 440 | 384 |
| 441 TEST_F(CustomButtonTest, HideInkDropWhenShowingContextMenu) { | 385 TEST_F(CustomButtonTest, HideInkDropWhenShowingContextMenu) { |
| 442 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); | 386 TestInkDrop* ink_drop = new TestInkDrop(); |
| 443 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate)); | 387 CreateButtonWithInkDrop(base::WrapUnique(ink_drop)); |
| 444 TestContextMenuController context_menu_controller; | 388 TestContextMenuController context_menu_controller; |
| 445 button()->set_context_menu_controller(&context_menu_controller); | 389 button()->set_context_menu_controller(&context_menu_controller); |
| 446 button()->set_hide_ink_drop_when_showing_context_menu(true); | 390 button()->set_hide_ink_drop_when_showing_context_menu(true); |
| 447 | 391 |
| 448 ink_drop_delegate->SetHovered(true); | 392 ink_drop->SetHovered(true); |
| 449 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); | 393 ink_drop->AnimateToState(InkDropState::ACTION_PENDING); |
| 450 | 394 |
| 451 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); | 395 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); |
| 452 | 396 |
| 453 EXPECT_FALSE(ink_drop_delegate->is_hovered()); | 397 EXPECT_FALSE(ink_drop->is_hovered()); |
| 454 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate->GetTargetInkDropState()); | 398 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); |
| 455 } | 399 } |
| 456 | 400 |
| 457 TEST_F(CustomButtonTest, DontHideInkDropWhenShowingContextMenu) { | 401 TEST_F(CustomButtonTest, DontHideInkDropWhenShowingContextMenu) { |
| 458 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); | 402 TestInkDrop* ink_drop = new TestInkDrop(); |
| 459 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate)); | 403 CreateButtonWithInkDrop(base::WrapUnique(ink_drop)); |
| 460 TestContextMenuController context_menu_controller; | 404 TestContextMenuController context_menu_controller; |
| 461 button()->set_context_menu_controller(&context_menu_controller); | 405 button()->set_context_menu_controller(&context_menu_controller); |
| 462 button()->set_hide_ink_drop_when_showing_context_menu(false); | 406 button()->set_hide_ink_drop_when_showing_context_menu(false); |
| 463 | 407 |
| 464 ink_drop_delegate->SetHovered(true); | 408 ink_drop->SetHovered(true); |
| 465 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); | 409 ink_drop->AnimateToState(InkDropState::ACTION_PENDING); |
| 466 | 410 |
| 467 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); | 411 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); |
| 468 | 412 |
| 469 EXPECT_TRUE(ink_drop_delegate->is_hovered()); | 413 EXPECT_TRUE(ink_drop->is_hovered()); |
| 470 EXPECT_EQ(InkDropState::ACTION_PENDING, | 414 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); |
| 471 ink_drop_delegate->GetTargetInkDropState()); | |
| 472 } | 415 } |
| 473 | 416 |
| 474 TEST_F(CustomButtonTest, HideInkDropOnBlur) { | 417 TEST_F(CustomButtonTest, HideInkDropOnBlur) { |
| 475 gfx::Point center(10, 10); | 418 gfx::Point center(10, 10); |
| 476 | 419 |
| 477 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); | 420 TestInkDrop* ink_drop = new TestInkDrop(); |
| 478 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate)); | 421 CreateButtonWithInkDrop(base::WrapUnique(ink_drop)); |
| 479 | 422 |
| 480 button()->OnFocus(); | 423 button()->OnFocus(); |
| 481 | 424 |
| 482 button()->OnMousePressed(ui::MouseEvent( | 425 button()->OnMousePressed(ui::MouseEvent( |
| 483 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 426 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 484 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 427 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 485 EXPECT_EQ(InkDropState::ACTION_PENDING, | 428 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); |
| 486 ink_drop_delegate->GetTargetInkDropState()); | |
| 487 | 429 |
| 488 button()->OnBlur(); | 430 button()->OnBlur(); |
| 489 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate->GetTargetInkDropState()); | 431 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); |
| 490 | 432 |
| 491 button()->OnMouseReleased(ui::MouseEvent( | 433 button()->OnMouseReleased(ui::MouseEvent( |
| 492 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 434 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 493 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 435 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 494 EXPECT_TRUE(button()->pressed()); | 436 EXPECT_TRUE(button()->pressed()); |
| 495 } | 437 } |
| 496 | 438 |
| 497 TEST_F(CustomButtonTest, InkDropAfterTryingToShowContextMenu) { | 439 TEST_F(CustomButtonTest, InkDropAfterTryingToShowContextMenu) { |
| 498 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); | 440 TestInkDrop* ink_drop = new TestInkDrop(); |
| 499 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate)); | 441 CreateButtonWithInkDrop(base::WrapUnique(ink_drop)); |
| 500 button()->set_context_menu_controller(nullptr); | 442 button()->set_context_menu_controller(nullptr); |
| 501 | 443 |
| 502 ink_drop_delegate->SetHovered(true); | 444 ink_drop->SetHovered(true); |
| 503 ink_drop_delegate->OnAction(InkDropState::ACTION_PENDING); | 445 ink_drop->AnimateToState(InkDropState::ACTION_PENDING); |
| 504 | 446 |
| 505 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); | 447 button()->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); |
| 506 | 448 |
| 507 EXPECT_TRUE(ink_drop_delegate->is_hovered()); | 449 EXPECT_TRUE(ink_drop->is_hovered()); |
| 508 EXPECT_EQ(InkDropState::ACTION_PENDING, | 450 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); |
| 509 ink_drop_delegate->GetTargetInkDropState()); | |
| 510 } | 451 } |
| 511 | 452 |
| 512 TEST_F(CustomButtonTest, InkDropShowHideOnMouseDragged) { | 453 TEST_F(CustomButtonTest, InkDropShowHideOnMouseDragged) { |
| 513 gfx::Point center(10, 10); | 454 gfx::Point center(10, 10); |
| 514 gfx::Point oob(-1, -1); | 455 gfx::Point oob(-1, -1); |
| 515 | 456 |
| 516 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); | 457 TestInkDrop* ink_drop = new TestInkDrop(); |
| 517 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate)); | 458 CreateButtonWithInkDrop(base::WrapUnique(ink_drop)); |
| 518 | 459 |
| 519 button()->OnMousePressed(ui::MouseEvent( | 460 button()->OnMousePressed(ui::MouseEvent( |
| 520 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 461 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 521 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 462 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 522 | 463 |
| 523 EXPECT_EQ(InkDropState::ACTION_PENDING, | 464 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); |
| 524 ink_drop_delegate->GetTargetInkDropState()); | |
| 525 | 465 |
| 526 button()->OnMouseDragged( | 466 button()->OnMouseDragged( |
| 527 ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), | 467 ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), |
| 528 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 468 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 529 | 469 |
| 530 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate->GetTargetInkDropState()); | 470 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); |
| 531 | 471 |
| 532 button()->OnMouseDragged(ui::MouseEvent( | 472 button()->OnMouseDragged(ui::MouseEvent( |
| 533 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 473 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 534 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 474 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 535 | 475 |
| 536 EXPECT_EQ(InkDropState::ACTION_PENDING, | 476 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); |
| 537 ink_drop_delegate->GetTargetInkDropState()); | |
| 538 | 477 |
| 539 button()->OnMouseDragged( | 478 button()->OnMouseDragged( |
| 540 ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), | 479 ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), |
| 541 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 480 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 542 | 481 |
| 543 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate->GetTargetInkDropState()); | 482 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); |
| 544 | 483 |
| 545 button()->OnMouseReleased( | 484 button()->OnMouseReleased( |
| 546 ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), | 485 ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), |
| 547 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 486 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 548 | 487 |
| 549 EXPECT_FALSE(button()->pressed()); | 488 EXPECT_FALSE(button()->pressed()); |
| 550 } | 489 } |
| 551 | 490 |
| 552 TEST_F(CustomButtonTest, InkDropStaysHiddenWhileDragging) { | 491 TEST_F(CustomButtonTest, InkDropStaysHiddenWhileDragging) { |
| 553 gfx::Point center(10, 10); | 492 gfx::Point center(10, 10); |
| 554 gfx::Point oob(-1, -1); | 493 gfx::Point oob(-1, -1); |
| 555 | 494 |
| 556 TestInkDropDelegate* ink_drop_delegate = new TestInkDropDelegate(); | 495 TestInkDrop* ink_drop = new TestInkDrop(); |
| 557 CreateButtonWithInkDrop(base::WrapUnique(ink_drop_delegate)); | 496 CreateButtonWithInkDrop(base::WrapUnique(ink_drop)); |
| 558 | 497 |
| 559 button()->OnMousePressed(ui::MouseEvent( | 498 button()->OnMousePressed(ui::MouseEvent( |
| 560 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 499 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 561 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 500 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 562 | 501 |
| 563 EXPECT_EQ(InkDropState::ACTION_PENDING, | 502 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); |
| 564 ink_drop_delegate->GetTargetInkDropState()); | |
| 565 | 503 |
| 566 SetDraggedView(button()); | 504 SetDraggedView(button()); |
| 567 widget()->SetCapture(button()); | 505 widget()->SetCapture(button()); |
| 568 widget()->ReleaseCapture(); | 506 widget()->ReleaseCapture(); |
| 569 | 507 |
| 570 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate->GetTargetInkDropState()); | 508 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); |
| 571 | 509 |
| 572 button()->OnMouseDragged( | 510 button()->OnMouseDragged( |
| 573 ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), | 511 ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), |
| 574 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 512 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 575 | 513 |
| 576 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate->GetTargetInkDropState()); | 514 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); |
| 577 | 515 |
| 578 button()->OnMouseDragged(ui::MouseEvent( | 516 button()->OnMouseDragged(ui::MouseEvent( |
| 579 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 517 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 580 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 518 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 581 | 519 |
| 582 EXPECT_EQ(InkDropState::HIDDEN, ink_drop_delegate->GetTargetInkDropState()); | 520 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); |
| 583 | 521 |
| 584 SetDraggedView(nullptr); | 522 SetDraggedView(nullptr); |
| 585 } | 523 } |
| 586 | 524 |
| 587 } // namespace views | 525 } // namespace views |
| OLD | NEW |