| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/message_center/views/notification_view.h" | 5 #include "ui/message_center/views/notification_view.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 widget()->Show(); | 449 widget()->Show(); |
| 450 | 450 |
| 451 EXPECT_EQ(views::CustomButton::STATE_NORMAL, | 451 EXPECT_EQ(views::CustomButton::STATE_NORMAL, |
| 452 notification_view()->action_buttons_[0]->state()); | 452 notification_view()->action_buttons_[0]->state()); |
| 453 | 453 |
| 454 // Now construct a mouse move event 1 pixel inside the boundary of the action | 454 // Now construct a mouse move event 1 pixel inside the boundary of the action |
| 455 // button. | 455 // button. |
| 456 gfx::Point cursor_location(1, 1); | 456 gfx::Point cursor_location(1, 1); |
| 457 views::View::ConvertPointToWidget(notification_view()->action_buttons_[0], | 457 views::View::ConvertPointToWidget(notification_view()->action_buttons_[0], |
| 458 &cursor_location); | 458 &cursor_location); |
| 459 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, | 459 ui::MouseEvent move( |
| 460 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 460 ui::ET_MOUSE_MOVED, cursor_location, cursor_location, |
| 461 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 462 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 461 widget()->OnMouseEvent(&move); | 463 widget()->OnMouseEvent(&move); |
| 462 | 464 |
| 463 EXPECT_EQ(views::CustomButton::STATE_HOVERED, | 465 EXPECT_EQ(views::CustomButton::STATE_HOVERED, |
| 464 notification_view()->action_buttons_[0]->state()); | 466 notification_view()->action_buttons_[0]->state()); |
| 465 | 467 |
| 466 notification_view()->CreateOrUpdateViews(*notification()); | 468 notification_view()->CreateOrUpdateViews(*notification()); |
| 467 | 469 |
| 468 EXPECT_EQ(views::CustomButton::STATE_HOVERED, | 470 EXPECT_EQ(views::CustomButton::STATE_HOVERED, |
| 469 notification_view()->action_buttons_[0]->state()); | 471 notification_view()->action_buttons_[0]->state()); |
| 470 | 472 |
| 471 // Now construct a mouse move event 1 pixel outside the boundary of the | 473 // Now construct a mouse move event 1 pixel outside the boundary of the |
| 472 // widget. | 474 // widget. |
| 473 cursor_location = gfx::Point(-1, -1); | 475 cursor_location = gfx::Point(-1, -1); |
| 474 move = ui::MouseEvent(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, | 476 move = ui::MouseEvent( |
| 475 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 477 ui::ET_MOUSE_MOVED, cursor_location, cursor_location, |
| 478 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 479 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 476 widget()->OnMouseEvent(&move); | 480 widget()->OnMouseEvent(&move); |
| 477 | 481 |
| 478 EXPECT_EQ(views::CustomButton::STATE_NORMAL, | 482 EXPECT_EQ(views::CustomButton::STATE_NORMAL, |
| 479 notification_view()->action_buttons_[0]->state()); | 483 notification_view()->action_buttons_[0]->state()); |
| 480 } | 484 } |
| 481 | 485 |
| 482 TEST_F(NotificationViewTest, UpdateButtonCountTest) { | 486 TEST_F(NotificationViewTest, UpdateButtonCountTest) { |
| 483 notification()->set_buttons(CreateButtons(2)); | 487 notification()->set_buttons(CreateButtons(2)); |
| 484 notification_view()->CreateOrUpdateViews(*notification()); | 488 notification_view()->CreateOrUpdateViews(*notification()); |
| 485 widget()->Show(); | 489 widget()->Show(); |
| 486 | 490 |
| 487 EXPECT_EQ(views::CustomButton::STATE_NORMAL, | 491 EXPECT_EQ(views::CustomButton::STATE_NORMAL, |
| 488 notification_view()->action_buttons_[0]->state()); | 492 notification_view()->action_buttons_[0]->state()); |
| 489 EXPECT_EQ(views::CustomButton::STATE_NORMAL, | 493 EXPECT_EQ(views::CustomButton::STATE_NORMAL, |
| 490 notification_view()->action_buttons_[1]->state()); | 494 notification_view()->action_buttons_[1]->state()); |
| 491 | 495 |
| 492 // Now construct a mouse move event 1 pixel inside the boundary of the action | 496 // Now construct a mouse move event 1 pixel inside the boundary of the action |
| 493 // button. | 497 // button. |
| 494 gfx::Point cursor_location(1, 1); | 498 gfx::Point cursor_location(1, 1); |
| 495 views::View::ConvertPointToScreen(notification_view()->action_buttons_[0], | 499 views::View::ConvertPointToScreen(notification_view()->action_buttons_[0], |
| 496 &cursor_location); | 500 &cursor_location); |
| 497 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, | 501 ui::MouseEvent move( |
| 498 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 502 ui::ET_MOUSE_MOVED, cursor_location, cursor_location, |
| 503 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 504 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 499 ui::EventDispatchDetails details = | 505 ui::EventDispatchDetails details = |
| 500 views::test::WidgetTest::GetEventSink(widget())->OnEventFromSource(&move); | 506 views::test::WidgetTest::GetEventSink(widget())->OnEventFromSource(&move); |
| 501 EXPECT_FALSE(details.dispatcher_destroyed); | 507 EXPECT_FALSE(details.dispatcher_destroyed); |
| 502 | 508 |
| 503 EXPECT_EQ(views::CustomButton::STATE_HOVERED, | 509 EXPECT_EQ(views::CustomButton::STATE_HOVERED, |
| 504 notification_view()->action_buttons_[0]->state()); | 510 notification_view()->action_buttons_[0]->state()); |
| 505 EXPECT_EQ(views::CustomButton::STATE_NORMAL, | 511 EXPECT_EQ(views::CustomButton::STATE_NORMAL, |
| 506 notification_view()->action_buttons_[1]->state()); | 512 notification_view()->action_buttons_[1]->state()); |
| 507 | 513 |
| 508 notification()->set_buttons(CreateButtons(1)); | 514 notification()->set_buttons(CreateButtons(1)); |
| 509 notification_view()->CreateOrUpdateViews(*notification()); | 515 notification_view()->CreateOrUpdateViews(*notification()); |
| 510 | 516 |
| 511 EXPECT_EQ(views::CustomButton::STATE_HOVERED, | 517 EXPECT_EQ(views::CustomButton::STATE_HOVERED, |
| 512 notification_view()->action_buttons_[0]->state()); | 518 notification_view()->action_buttons_[0]->state()); |
| 513 EXPECT_EQ(1u, notification_view()->action_buttons_.size()); | 519 EXPECT_EQ(1u, notification_view()->action_buttons_.size()); |
| 514 | 520 |
| 515 // Now construct a mouse move event 1 pixel outside the boundary of the | 521 // Now construct a mouse move event 1 pixel outside the boundary of the |
| 516 // widget. | 522 // widget. |
| 517 cursor_location = gfx::Point(-1, -1); | 523 cursor_location = gfx::Point(-1, -1); |
| 518 move = ui::MouseEvent(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, | 524 move = ui::MouseEvent( |
| 519 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 525 ui::ET_MOUSE_MOVED, cursor_location, cursor_location, |
| 526 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 527 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 520 widget()->OnMouseEvent(&move); | 528 widget()->OnMouseEvent(&move); |
| 521 | 529 |
| 522 EXPECT_EQ(views::CustomButton::STATE_NORMAL, | 530 EXPECT_EQ(views::CustomButton::STATE_NORMAL, |
| 523 notification_view()->action_buttons_[0]->state()); | 531 notification_view()->action_buttons_[0]->state()); |
| 524 } | 532 } |
| 525 | 533 |
| 526 TEST_F(NotificationViewTest, SettingsButtonTest) { | 534 TEST_F(NotificationViewTest, SettingsButtonTest) { |
| 527 scoped_refptr<NotificationSettingsDelegate> delegate = | 535 scoped_refptr<NotificationSettingsDelegate> delegate = |
| 528 new NotificationSettingsDelegate(); | 536 new NotificationSettingsDelegate(); |
| 529 Notification notf(NOTIFICATION_TYPE_BASE_FORMAT, | 537 Notification notf(NOTIFICATION_TYPE_BASE_FORMAT, |
| 530 std::string("notification id"), base::UTF8ToUTF16("title"), | 538 std::string("notification id"), base::UTF8ToUTF16("title"), |
| 531 base::UTF8ToUTF16("message"), CreateTestImage(80, 80), | 539 base::UTF8ToUTF16("message"), CreateTestImage(80, 80), |
| 532 base::UTF8ToUTF16("display source"), | 540 base::UTF8ToUTF16("display source"), |
| 533 GURL("https://hello.com"), | 541 GURL("https://hello.com"), |
| 534 NotifierId(NotifierId::APPLICATION, "extension_id"), | 542 NotifierId(NotifierId::APPLICATION, "extension_id"), |
| 535 *data(), delegate.get()); | 543 *data(), delegate.get()); |
| 536 notification_view()->CreateOrUpdateViews(notf); | 544 notification_view()->CreateOrUpdateViews(notf); |
| 537 widget()->Show(); | 545 widget()->Show(); |
| 538 notification_view()->Layout(); | 546 notification_view()->Layout(); |
| 539 | 547 |
| 540 EXPECT_TRUE(NULL != notification_view()->settings_button_view_); | 548 EXPECT_TRUE(NULL != notification_view()->settings_button_view_); |
| 541 EXPECT_EQ(views::CustomButton::STATE_NORMAL, | 549 EXPECT_EQ(views::CustomButton::STATE_NORMAL, |
| 542 notification_view()->settings_button_view_->state()); | 550 notification_view()->settings_button_view_->state()); |
| 543 | 551 |
| 544 // Now construct a mouse move event 1 pixel inside the boundary of the action | 552 // Now construct a mouse move event 1 pixel inside the boundary of the action |
| 545 // button. | 553 // button. |
| 546 gfx::Point cursor_location(1, 1); | 554 gfx::Point cursor_location(1, 1); |
| 547 views::View::ConvertPointToScreen(notification_view()->settings_button_view_, | 555 views::View::ConvertPointToScreen(notification_view()->settings_button_view_, |
| 548 &cursor_location); | 556 &cursor_location); |
| 549 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, | 557 ui::MouseEvent move( |
| 550 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 558 ui::ET_MOUSE_MOVED, cursor_location, cursor_location, |
| 559 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 560 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 551 widget()->OnMouseEvent(&move); | 561 widget()->OnMouseEvent(&move); |
| 552 ui::EventDispatchDetails details = | 562 ui::EventDispatchDetails details = |
| 553 views::test::WidgetTest::GetEventSink(widget())->OnEventFromSource(&move); | 563 views::test::WidgetTest::GetEventSink(widget())->OnEventFromSource(&move); |
| 554 EXPECT_FALSE(details.dispatcher_destroyed); | 564 EXPECT_FALSE(details.dispatcher_destroyed); |
| 555 | 565 |
| 556 EXPECT_EQ(views::CustomButton::STATE_HOVERED, | 566 EXPECT_EQ(views::CustomButton::STATE_HOVERED, |
| 557 notification_view()->settings_button_view_->state()); | 567 notification_view()->settings_button_view_->state()); |
| 558 | 568 |
| 559 // Now construct a mouse move event 1 pixel outside the boundary of the | 569 // Now construct a mouse move event 1 pixel outside the boundary of the |
| 560 // widget. | 570 // widget. |
| 561 cursor_location = gfx::Point(-1, -1); | 571 cursor_location = gfx::Point(-1, -1); |
| 562 move = ui::MouseEvent(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, | 572 move = ui::MouseEvent( |
| 563 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 573 ui::ET_MOUSE_MOVED, cursor_location, cursor_location, |
| 574 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 575 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 564 widget()->OnMouseEvent(&move); | 576 widget()->OnMouseEvent(&move); |
| 565 | 577 |
| 566 EXPECT_EQ(views::CustomButton::STATE_NORMAL, | 578 EXPECT_EQ(views::CustomButton::STATE_NORMAL, |
| 567 notification_view()->settings_button_view_->state()); | 579 notification_view()->settings_button_view_->state()); |
| 568 } | 580 } |
| 569 | 581 |
| 570 TEST_F(NotificationViewTest, ViewOrderingTest) { | 582 TEST_F(NotificationViewTest, ViewOrderingTest) { |
| 571 // Tests that views are created in the correct vertical order. | 583 // Tests that views are created in the correct vertical order. |
| 572 notification()->set_buttons(CreateButtons(2)); | 584 notification()->set_buttons(CreateButtons(2)); |
| 573 | 585 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 TEST_F(NotificationViewTest, Pinned) { | 721 TEST_F(NotificationViewTest, Pinned) { |
| 710 notification()->set_pinned(true); | 722 notification()->set_pinned(true); |
| 711 | 723 |
| 712 UpdateNotificationViews(); | 724 UpdateNotificationViews(); |
| 713 EXPECT_EQ(NULL, GetCloseButton()); | 725 EXPECT_EQ(NULL, GetCloseButton()); |
| 714 } | 726 } |
| 715 | 727 |
| 716 #endif // defined(OS_CHROMEOS) | 728 #endif // defined(OS_CHROMEOS) |
| 717 | 729 |
| 718 } // namespace message_center | 730 } // namespace message_center |
| OLD | NEW |