| 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 "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 #endif // !defined(OS_MACOSX) || defined(USE_AURA) | 238 #endif // !defined(OS_MACOSX) || defined(USE_AURA) |
| 239 } | 239 } |
| 240 | 240 |
| 241 // Tests the different types of NotifyActions. | 241 // Tests the different types of NotifyActions. |
| 242 TEST_F(CustomButtonTest, NotifyAction) { | 242 TEST_F(CustomButtonTest, NotifyAction) { |
| 243 gfx::Point center(10, 10); | 243 gfx::Point center(10, 10); |
| 244 | 244 |
| 245 // By default the button should notify its listener on mouse release. | 245 // By default the button should notify its listener on mouse release. |
| 246 button()->OnMousePressed(ui::MouseEvent( | 246 button()->OnMousePressed(ui::MouseEvent( |
| 247 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 247 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 248 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 248 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 249 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 249 EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state()); | 250 EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state()); |
| 250 EXPECT_FALSE(button()->pressed()); | 251 EXPECT_FALSE(button()->pressed()); |
| 251 | 252 |
| 252 button()->OnMouseReleased(ui::MouseEvent( | 253 button()->OnMouseReleased(ui::MouseEvent( |
| 253 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), | 254 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), |
| 254 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 255 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 256 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 255 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state()); | 257 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state()); |
| 256 EXPECT_TRUE(button()->pressed()); | 258 EXPECT_TRUE(button()->pressed()); |
| 257 | 259 |
| 258 // Set the notify action to its listener on mouse press. | 260 // Set the notify action to its listener on mouse press. |
| 259 button()->Reset(); | 261 button()->Reset(); |
| 260 button()->set_notify_action(CustomButton::NOTIFY_ON_PRESS); | 262 button()->set_notify_action(CustomButton::NOTIFY_ON_PRESS); |
| 261 button()->OnMousePressed(ui::MouseEvent( | 263 button()->OnMousePressed(ui::MouseEvent( |
| 262 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 264 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 263 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 265 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 266 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 264 EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state()); | 267 EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state()); |
| 265 EXPECT_TRUE(button()->pressed()); | 268 EXPECT_TRUE(button()->pressed()); |
| 266 | 269 |
| 267 // The button should no longer notify on mouse release. | 270 // The button should no longer notify on mouse release. |
| 268 button()->Reset(); | 271 button()->Reset(); |
| 269 button()->OnMouseReleased(ui::MouseEvent( | 272 button()->OnMouseReleased(ui::MouseEvent( |
| 270 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), | 273 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), |
| 271 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 274 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 275 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 272 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state()); | 276 EXPECT_EQ(CustomButton::STATE_HOVERED, button()->state()); |
| 273 EXPECT_FALSE(button()->pressed()); | 277 EXPECT_FALSE(button()->pressed()); |
| 274 } | 278 } |
| 275 | 279 |
| 276 // Tests that OnClickCanceled gets called when NotifyClick is not expected | 280 // Tests that OnClickCanceled gets called when NotifyClick is not expected |
| 277 // anymore. | 281 // anymore. |
| 278 TEST_F(CustomButtonTest, NotifyActionNoClick) { | 282 TEST_F(CustomButtonTest, NotifyActionNoClick) { |
| 279 gfx::Point center(10, 10); | 283 gfx::Point center(10, 10); |
| 280 | 284 |
| 281 // By default the button should notify its listener on mouse release. | 285 // By default the button should notify its listener on mouse release. |
| 282 button()->OnMousePressed(ui::MouseEvent( | 286 button()->OnMousePressed(ui::MouseEvent( |
| 283 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 287 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 284 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON)); | 288 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON, |
| 289 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 285 EXPECT_FALSE(button()->canceled()); | 290 EXPECT_FALSE(button()->canceled()); |
| 286 | 291 |
| 287 button()->OnMouseReleased(ui::MouseEvent( | 292 button()->OnMouseReleased(ui::MouseEvent( |
| 288 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), | 293 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), |
| 289 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON)); | 294 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON, |
| 295 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 290 EXPECT_TRUE(button()->canceled()); | 296 EXPECT_TRUE(button()->canceled()); |
| 291 | 297 |
| 292 // Set the notify action to its listener on mouse press. | 298 // Set the notify action to its listener on mouse press. |
| 293 button()->Reset(); | 299 button()->Reset(); |
| 294 button()->set_notify_action(CustomButton::NOTIFY_ON_PRESS); | 300 button()->set_notify_action(CustomButton::NOTIFY_ON_PRESS); |
| 295 button()->OnMousePressed(ui::MouseEvent( | 301 button()->OnMousePressed(ui::MouseEvent( |
| 296 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 302 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 297 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON)); | 303 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON, |
| 304 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 298 // OnClickCanceled is only sent on mouse release. | 305 // OnClickCanceled is only sent on mouse release. |
| 299 EXPECT_FALSE(button()->canceled()); | 306 EXPECT_FALSE(button()->canceled()); |
| 300 | 307 |
| 301 // The button should no longer notify on mouse release. | 308 // The button should no longer notify on mouse release. |
| 302 button()->Reset(); | 309 button()->Reset(); |
| 303 button()->OnMouseReleased(ui::MouseEvent( | 310 button()->OnMouseReleased(ui::MouseEvent( |
| 304 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), | 311 ui::ET_MOUSE_RELEASED, center, center, ui::EventTimeForNow(), |
| 305 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON)); | 312 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON, |
| 313 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 306 EXPECT_FALSE(button()->canceled()); | 314 EXPECT_FALSE(button()->canceled()); |
| 307 } | 315 } |
| 308 | 316 |
| 309 // No touch on desktop Mac. Tracked in http://crbug.com/445520. | 317 // No touch on desktop Mac. Tracked in http://crbug.com/445520. |
| 310 #if !defined(OS_MACOSX) || defined(USE_AURA) | 318 #if !defined(OS_MACOSX) || defined(USE_AURA) |
| 311 | 319 |
| 312 namespace { | 320 namespace { |
| 313 | 321 |
| 314 void PerformGesture(CustomButton* button, ui::EventType event_type) { | 322 void PerformGesture(CustomButton* button, ui::EventType event_type) { |
| 315 ui::GestureEventDetails gesture_details(event_type); | 323 ui::GestureEventDetails gesture_details(event_type); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 TEST_F(CustomButtonTest, HideInkDropOnBlur) { | 450 TEST_F(CustomButtonTest, HideInkDropOnBlur) { |
| 443 gfx::Point center(10, 10); | 451 gfx::Point center(10, 10); |
| 444 | 452 |
| 445 TestInkDrop* ink_drop = new TestInkDrop(); | 453 TestInkDrop* ink_drop = new TestInkDrop(); |
| 446 CreateButtonWithInkDrop(base::WrapUnique(ink_drop), false); | 454 CreateButtonWithInkDrop(base::WrapUnique(ink_drop), false); |
| 447 | 455 |
| 448 button()->OnFocus(); | 456 button()->OnFocus(); |
| 449 | 457 |
| 450 button()->OnMousePressed(ui::MouseEvent( | 458 button()->OnMousePressed(ui::MouseEvent( |
| 451 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 459 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 452 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 460 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 461 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 453 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); | 462 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); |
| 454 | 463 |
| 455 button()->OnBlur(); | 464 button()->OnBlur(); |
| 456 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); | 465 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); |
| 457 | 466 |
| 458 button()->OnMouseReleased(ui::MouseEvent( | 467 button()->OnMouseReleased(ui::MouseEvent( |
| 459 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 468 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 460 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 469 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 470 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 461 EXPECT_TRUE(button()->pressed()); | 471 EXPECT_TRUE(button()->pressed()); |
| 462 } | 472 } |
| 463 | 473 |
| 464 TEST_F(CustomButtonTest, HideInkDropHighlightOnDisable) { | 474 TEST_F(CustomButtonTest, HideInkDropHighlightOnDisable) { |
| 465 TestInkDrop* ink_drop = new TestInkDrop(); | 475 TestInkDrop* ink_drop = new TestInkDrop(); |
| 466 CreateButtonWithInkDrop(base::WrapUnique(ink_drop), false); | 476 CreateButtonWithInkDrop(base::WrapUnique(ink_drop), false); |
| 467 | 477 |
| 468 ui::test::EventGenerator generator(widget()->GetNativeWindow()); | 478 ui::test::EventGenerator generator(widget()->GetNativeWindow()); |
| 469 generator.MoveMouseToInHost(10, 10); | 479 generator.MoveMouseToInHost(10, 10); |
| 470 EXPECT_TRUE(ink_drop->is_hovered()); | 480 EXPECT_TRUE(ink_drop->is_hovered()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 493 TEST_F(CustomButtonTest, InkDropShowHideOnMouseDraggedNotifyOnRelease) { | 503 TEST_F(CustomButtonTest, InkDropShowHideOnMouseDraggedNotifyOnRelease) { |
| 494 gfx::Point center(10, 10); | 504 gfx::Point center(10, 10); |
| 495 gfx::Point oob(-1, -1); | 505 gfx::Point oob(-1, -1); |
| 496 | 506 |
| 497 TestInkDrop* ink_drop = new TestInkDrop(); | 507 TestInkDrop* ink_drop = new TestInkDrop(); |
| 498 CreateButtonWithInkDrop(base::WrapUnique(ink_drop), false); | 508 CreateButtonWithInkDrop(base::WrapUnique(ink_drop), false); |
| 499 button()->set_notify_action(CustomButton::NOTIFY_ON_RELEASE); | 509 button()->set_notify_action(CustomButton::NOTIFY_ON_RELEASE); |
| 500 | 510 |
| 501 button()->OnMousePressed(ui::MouseEvent( | 511 button()->OnMousePressed(ui::MouseEvent( |
| 502 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 512 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 503 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 513 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 514 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 504 | 515 |
| 505 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); | 516 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); |
| 506 | 517 |
| 507 button()->OnMouseDragged( | 518 button()->OnMouseDragged(ui::MouseEvent( |
| 508 ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), | 519 ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), |
| 509 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 520 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 521 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 510 | 522 |
| 511 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); | 523 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); |
| 512 | 524 |
| 513 button()->OnMouseDragged(ui::MouseEvent( | 525 button()->OnMouseDragged(ui::MouseEvent( |
| 514 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 526 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 515 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 527 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 528 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 516 | 529 |
| 517 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); | 530 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); |
| 518 | 531 |
| 519 button()->OnMouseDragged( | 532 button()->OnMouseDragged(ui::MouseEvent( |
| 520 ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), | 533 ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), |
| 521 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 534 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 535 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 522 | 536 |
| 523 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); | 537 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); |
| 524 | 538 |
| 525 button()->OnMouseReleased( | 539 button()->OnMouseReleased(ui::MouseEvent( |
| 526 ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), | 540 ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), |
| 527 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 541 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 542 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 528 | 543 |
| 529 EXPECT_FALSE(button()->pressed()); | 544 EXPECT_FALSE(button()->pressed()); |
| 530 } | 545 } |
| 531 | 546 |
| 532 // Tests that when button is set to notify on press, dragging mouse out and back | 547 // Tests that when button is set to notify on press, dragging mouse out and back |
| 533 // does not change the ink drop state. | 548 // does not change the ink drop state. |
| 534 TEST_F(CustomButtonTest, InkDropShowHideOnMouseDraggedNotifyOnPress) { | 549 TEST_F(CustomButtonTest, InkDropShowHideOnMouseDraggedNotifyOnPress) { |
| 535 gfx::Point center(10, 10); | 550 gfx::Point center(10, 10); |
| 536 gfx::Point oob(-1, -1); | 551 gfx::Point oob(-1, -1); |
| 537 | 552 |
| 538 TestInkDrop* ink_drop = new TestInkDrop(); | 553 TestInkDrop* ink_drop = new TestInkDrop(); |
| 539 CreateButtonWithInkDrop(base::WrapUnique(ink_drop), true); | 554 CreateButtonWithInkDrop(base::WrapUnique(ink_drop), true); |
| 540 button()->set_notify_action(CustomButton::NOTIFY_ON_PRESS); | 555 button()->set_notify_action(CustomButton::NOTIFY_ON_PRESS); |
| 541 | 556 |
| 542 button()->OnMousePressed(ui::MouseEvent( | 557 button()->OnMousePressed(ui::MouseEvent( |
| 543 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 558 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 544 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 559 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 560 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 545 | 561 |
| 546 EXPECT_EQ(InkDropState::ACTION_TRIGGERED, ink_drop->GetTargetInkDropState()); | 562 EXPECT_EQ(InkDropState::ACTION_TRIGGERED, ink_drop->GetTargetInkDropState()); |
| 547 EXPECT_TRUE(button()->pressed()); | 563 EXPECT_TRUE(button()->pressed()); |
| 548 | 564 |
| 549 button()->OnMouseDragged( | 565 button()->OnMouseDragged(ui::MouseEvent( |
| 550 ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), | 566 ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), |
| 551 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 567 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 568 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 552 | 569 |
| 553 EXPECT_EQ(InkDropState::ACTION_TRIGGERED, ink_drop->GetTargetInkDropState()); | 570 EXPECT_EQ(InkDropState::ACTION_TRIGGERED, ink_drop->GetTargetInkDropState()); |
| 554 | 571 |
| 555 button()->OnMouseDragged(ui::MouseEvent( | 572 button()->OnMouseDragged(ui::MouseEvent( |
| 556 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 573 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 557 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 574 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 575 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 558 | 576 |
| 559 EXPECT_EQ(InkDropState::ACTION_TRIGGERED, ink_drop->GetTargetInkDropState()); | 577 EXPECT_EQ(InkDropState::ACTION_TRIGGERED, ink_drop->GetTargetInkDropState()); |
| 560 | 578 |
| 561 button()->OnMouseDragged( | 579 button()->OnMouseDragged(ui::MouseEvent( |
| 562 ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), | 580 ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), |
| 563 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 581 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 582 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 564 | 583 |
| 565 EXPECT_EQ(InkDropState::ACTION_TRIGGERED, ink_drop->GetTargetInkDropState()); | 584 EXPECT_EQ(InkDropState::ACTION_TRIGGERED, ink_drop->GetTargetInkDropState()); |
| 566 | 585 |
| 567 button()->OnMouseReleased( | 586 button()->OnMouseReleased(ui::MouseEvent( |
| 568 ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), | 587 ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), |
| 569 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 588 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 589 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 570 | 590 |
| 571 EXPECT_EQ(InkDropState::ACTION_TRIGGERED, ink_drop->GetTargetInkDropState()); | 591 EXPECT_EQ(InkDropState::ACTION_TRIGGERED, ink_drop->GetTargetInkDropState()); |
| 572 } | 592 } |
| 573 | 593 |
| 574 TEST_F(CustomButtonTest, InkDropStaysHiddenWhileDragging) { | 594 TEST_F(CustomButtonTest, InkDropStaysHiddenWhileDragging) { |
| 575 gfx::Point center(10, 10); | 595 gfx::Point center(10, 10); |
| 576 gfx::Point oob(-1, -1); | 596 gfx::Point oob(-1, -1); |
| 577 | 597 |
| 578 TestInkDrop* ink_drop = new TestInkDrop(); | 598 TestInkDrop* ink_drop = new TestInkDrop(); |
| 579 CreateButtonWithInkDrop(base::WrapUnique(ink_drop), false); | 599 CreateButtonWithInkDrop(base::WrapUnique(ink_drop), false); |
| 580 | 600 |
| 581 button()->OnMousePressed(ui::MouseEvent( | 601 button()->OnMousePressed(ui::MouseEvent( |
| 582 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 602 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 583 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 603 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 604 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 584 | 605 |
| 585 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); | 606 EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState()); |
| 586 | 607 |
| 587 SetDraggedView(button()); | 608 SetDraggedView(button()); |
| 588 widget()->SetCapture(button()); | 609 widget()->SetCapture(button()); |
| 589 widget()->ReleaseCapture(); | 610 widget()->ReleaseCapture(); |
| 590 | 611 |
| 591 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); | 612 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); |
| 592 | 613 |
| 593 button()->OnMouseDragged( | 614 button()->OnMouseDragged(ui::MouseEvent( |
| 594 ui::MouseEvent(ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), | 615 ui::ET_MOUSE_PRESSED, oob, oob, ui::EventTimeForNow(), |
| 595 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 616 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 617 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 596 | 618 |
| 597 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); | 619 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); |
| 598 | 620 |
| 599 button()->OnMouseDragged(ui::MouseEvent( | 621 button()->OnMouseDragged(ui::MouseEvent( |
| 600 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), | 622 ui::ET_MOUSE_PRESSED, center, center, ui::EventTimeForNow(), |
| 601 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 623 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
| 624 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE))); |
| 602 | 625 |
| 603 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); | 626 EXPECT_EQ(InkDropState::HIDDEN, ink_drop->GetTargetInkDropState()); |
| 604 | 627 |
| 605 SetDraggedView(nullptr); | 628 SetDraggedView(nullptr); |
| 606 } | 629 } |
| 607 | 630 |
| 608 // Test that hiding or closing a Widget doesn't attempt to add a layer due to | 631 // Test that hiding or closing a Widget doesn't attempt to add a layer due to |
| 609 // changed visibility states. | 632 // changed visibility states. |
| 610 TEST_F(CustomButtonTest, NoLayerAddedForWidgetVisibilityChanges) { | 633 TEST_F(CustomButtonTest, NoLayerAddedForWidgetVisibilityChanges) { |
| 611 CreateButtonWithRealInkDrop(); | 634 CreateButtonWithRealInkDrop(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state()); | 712 EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state()); |
| 690 EXPECT_TRUE(button()->pressed()); | 713 EXPECT_TRUE(button()->pressed()); |
| 691 #endif | 714 #endif |
| 692 | 715 |
| 693 ui::KeyEvent return_release(ui::ET_KEY_RELEASED, ui::VKEY_RETURN, | 716 ui::KeyEvent return_release(ui::ET_KEY_RELEASED, ui::VKEY_RETURN, |
| 694 ui::EF_NONE); | 717 ui::EF_NONE); |
| 695 EXPECT_FALSE(button()->OnKeyReleased(return_release)); | 718 EXPECT_FALSE(button()->OnKeyReleased(return_release)); |
| 696 } | 719 } |
| 697 | 720 |
| 698 } // namespace views | 721 } // namespace views |
| OLD | NEW |