| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/message_center_view.h" | 5 #include "ui/message_center/views/message_center_view.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/run_loop.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/message_center/fake_message_center.h" | 16 #include "ui/message_center/fake_message_center.h" |
| 16 #include "ui/message_center/message_center_style.h" | 17 #include "ui/message_center/message_center_style.h" |
| 17 #include "ui/message_center/notification.h" | 18 #include "ui/message_center/notification.h" |
| 18 #include "ui/message_center/notification_list.h" | 19 #include "ui/message_center/notification_list.h" |
| 19 #include "ui/message_center/notification_types.h" | 20 #include "ui/message_center/notification_types.h" |
| 20 #include "ui/message_center/views/message_center_button_bar.h" | 21 #include "ui/message_center/views/message_center_button_bar.h" |
| 21 #include "ui/message_center/views/message_center_controller.h" | 22 #include "ui/message_center/views/message_center_controller.h" |
| 22 #include "ui/message_center/views/message_list_view.h" | 23 #include "ui/message_center/views/message_list_view.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 223 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 223 params.bounds = gfx::Rect(50, 50, 650, 650); | 224 params.bounds = gfx::Rect(50, 50, 650, 650); |
| 224 widget_->Init(params); | 225 widget_->Init(params); |
| 225 views::View* root = widget_->GetRootView(); | 226 views::View* root = widget_->GetRootView(); |
| 226 root->AddChildView(message_center_view_.get()); | 227 root->AddChildView(message_center_view_.get()); |
| 227 widget_->Show(); | 228 widget_->Show(); |
| 228 widget_->Activate(); | 229 widget_->Activate(); |
| 229 | 230 |
| 230 // Wait until the animation finishes if available. | 231 // Wait until the animation finishes if available. |
| 231 if (GetAnimator()->IsAnimating()) | 232 if (GetAnimator()->IsAnimating()) |
| 232 base::MessageLoop::current()->Run(); | 233 base::RunLoop().Run(); |
| 233 } | 234 } |
| 234 | 235 |
| 235 void MessageCenterViewTest::TearDown() { | 236 void MessageCenterViewTest::TearDown() { |
| 236 widget_->CloseNow(); | 237 widget_->CloseNow(); |
| 237 widget_.reset(); | 238 widget_.reset(); |
| 238 message_center_view_.reset(); | 239 message_center_view_.reset(); |
| 239 base::STLDeleteElements(¬ifications_); | 240 base::STLDeleteElements(¬ifications_); |
| 240 views::ViewsTestBase::TearDown(); | 241 views::ViewsTestBase::TearDown(); |
| 241 } | 242 } |
| 242 | 243 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) + | 433 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) + |
| 433 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) + | 434 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) + |
| 434 GetMessageListView()->GetInsets().height()); | 435 GetMessageListView()->GetInsets().height()); |
| 435 | 436 |
| 436 int previous_height = GetMessageListView()->height(); | 437 int previous_height = GetMessageListView()->height(); |
| 437 | 438 |
| 438 UpdateNotification(kNotificationId2, std::move(notification)); | 439 UpdateNotification(kNotificationId2, std::move(notification)); |
| 439 | 440 |
| 440 // Wait until the animation finishes if available. | 441 // Wait until the animation finishes if available. |
| 441 if (GetAnimator()->IsAnimating()) | 442 if (GetAnimator()->IsAnimating()) |
| 442 base::MessageLoop::current()->Run(); | 443 base::RunLoop().Run(); |
| 443 | 444 |
| 444 EXPECT_EQ(2, GetMessageListView()->child_count()); | 445 EXPECT_EQ(2, GetMessageListView()->child_count()); |
| 445 EXPECT_EQ(GetMessageListView()->height(), | 446 EXPECT_EQ(GetMessageListView()->height(), |
| 446 GetCalculatedMessageListViewHeight()); | 447 GetCalculatedMessageListViewHeight()); |
| 447 | 448 |
| 448 // The size must be changed, since the new string is longer than the old one. | 449 // The size must be changed, since the new string is longer than the old one. |
| 449 EXPECT_NE(previous_height, GetMessageListView()->height()); | 450 EXPECT_NE(previous_height, GetMessageListView()->height()); |
| 450 | 451 |
| 451 EXPECT_EQ( | 452 EXPECT_EQ( |
| 452 GetMessageListView()->height(), | 453 GetMessageListView()->height(), |
| 453 GetNotificationView(kNotificationId1)->GetHeightForWidth(width) + | 454 GetNotificationView(kNotificationId1)->GetHeightForWidth(width) + |
| 454 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) + | 455 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()) + |
| 455 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) + | 456 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) + |
| 456 GetMessageListView()->GetInsets().height()); | 457 GetMessageListView()->GetInsets().height()); |
| 457 } | 458 } |
| 458 | 459 |
| 459 TEST_F(MessageCenterViewTest, SizeAfterRemove) { | 460 TEST_F(MessageCenterViewTest, SizeAfterRemove) { |
| 460 EXPECT_EQ(2, GetMessageListView()->child_count()); | 461 EXPECT_EQ(2, GetMessageListView()->child_count()); |
| 461 RemoveNotification(kNotificationId1, false); | 462 RemoveNotification(kNotificationId1, false); |
| 462 | 463 |
| 463 // Wait until the animation finishes if available. | 464 // Wait until the animation finishes if available. |
| 464 if (GetAnimator()->IsAnimating()) | 465 if (GetAnimator()->IsAnimating()) |
| 465 base::MessageLoop::current()->Run(); | 466 base::RunLoop().Run(); |
| 466 | 467 |
| 467 EXPECT_EQ(1, GetMessageListView()->child_count()); | 468 EXPECT_EQ(1, GetMessageListView()->child_count()); |
| 468 | 469 |
| 469 int width = | 470 int width = |
| 470 GetMessageListView()->width() - GetMessageListView()->GetInsets().width(); | 471 GetMessageListView()->width() - GetMessageListView()->GetInsets().width(); |
| 471 EXPECT_FALSE(GetNotificationView(kNotificationId1)); | 472 EXPECT_FALSE(GetNotificationView(kNotificationId1)); |
| 472 EXPECT_TRUE(GetNotificationView(kNotificationId2)); | 473 EXPECT_TRUE(GetNotificationView(kNotificationId2)); |
| 473 EXPECT_EQ(GetMessageListView()->height(), | 474 EXPECT_EQ(GetMessageListView()->height(), |
| 474 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) + | 475 GetNotificationView(kNotificationId2)->GetHeightForWidth(width) + |
| 475 GetMessageListView()->GetInsets().height()); | 476 GetMessageListView()->GetInsets().height()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 490 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2), | 491 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId2), |
| 491 base::UTF8ToUTF16("title2"), | 492 base::UTF8ToUTF16("title2"), |
| 492 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), | 493 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), |
| 493 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), | 494 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), |
| 494 NotifierId(NotifierId::APPLICATION, "extension_id"), | 495 NotifierId(NotifierId::APPLICATION, "extension_id"), |
| 495 message_center::RichNotificationData(), NULL)); | 496 message_center::RichNotificationData(), NULL)); |
| 496 UpdateNotification(kNotificationId2, std::move(notification)); | 497 UpdateNotification(kNotificationId2, std::move(notification)); |
| 497 | 498 |
| 498 // Wait until the animation finishes if available. | 499 // Wait until the animation finishes if available. |
| 499 if (GetAnimator()->IsAnimating()) | 500 if (GetAnimator()->IsAnimating()) |
| 500 base::MessageLoop::current()->Run(); | 501 base::RunLoop().Run(); |
| 501 | 502 |
| 502 // The vertical position of the target from bottom should be kept over change. | 503 // The vertical position of the target from bottom should be kept over change. |
| 503 int current_vertical_pos_from_bottom = | 504 int current_vertical_pos_from_bottom = |
| 504 GetMessageListView()->height() - | 505 GetMessageListView()->height() - |
| 505 GetNotificationView(kNotificationId1)->bounds().y(); | 506 GetNotificationView(kNotificationId1)->bounds().y(); |
| 506 EXPECT_EQ(previous_vertical_pos_from_bottom, | 507 EXPECT_EQ(previous_vertical_pos_from_bottom, |
| 507 current_vertical_pos_from_bottom); | 508 current_vertical_pos_from_bottom); |
| 508 } | 509 } |
| 509 | 510 |
| 510 TEST_F(MessageCenterViewTest, PositionAfterRemove) { | 511 TEST_F(MessageCenterViewTest, PositionAfterRemove) { |
| 511 // Make sure that the notification 2 is placed above the notification 1. | 512 // Make sure that the notification 2 is placed above the notification 1. |
| 512 EXPECT_LT(GetNotificationView(kNotificationId2)->bounds().y(), | 513 EXPECT_LT(GetNotificationView(kNotificationId2)->bounds().y(), |
| 513 GetNotificationView(kNotificationId1)->bounds().y()); | 514 GetNotificationView(kNotificationId1)->bounds().y()); |
| 514 | 515 |
| 515 GetMessageListView()->SetRepositionTargetForTest( | 516 GetMessageListView()->SetRepositionTargetForTest( |
| 516 GetNotificationView(kNotificationId2)->bounds()); | 517 GetNotificationView(kNotificationId2)->bounds()); |
| 517 int previous_height = GetMessageListView()->height(); | 518 int previous_height = GetMessageListView()->height(); |
| 518 int previous_notification2_y = | 519 int previous_notification2_y = |
| 519 GetNotificationView(kNotificationId2)->bounds().y(); | 520 GetNotificationView(kNotificationId2)->bounds().y(); |
| 520 int previous_notification2_height = | 521 int previous_notification2_height = |
| 521 GetNotificationView(kNotificationId2)->bounds().height(); | 522 GetNotificationView(kNotificationId2)->bounds().height(); |
| 522 | 523 |
| 523 EXPECT_EQ(2, GetMessageListView()->child_count()); | 524 EXPECT_EQ(2, GetMessageListView()->child_count()); |
| 524 RemoveNotification(kNotificationId2, false); | 525 RemoveNotification(kNotificationId2, false); |
| 525 | 526 |
| 526 // Wait until the animation finishes if available. | 527 // Wait until the animation finishes if available. |
| 527 if (GetAnimator()->IsAnimating()) | 528 if (GetAnimator()->IsAnimating()) |
| 528 base::MessageLoop::current()->Run(); | 529 base::RunLoop().Run(); |
| 529 | 530 |
| 530 EXPECT_EQ(1, GetMessageListView()->child_count()); | 531 EXPECT_EQ(1, GetMessageListView()->child_count()); |
| 531 | 532 |
| 532 // Confirm that notification 1 is moved up to the place on which the | 533 // Confirm that notification 1 is moved up to the place on which the |
| 533 // notification 2 was. | 534 // notification 2 was. |
| 534 EXPECT_EQ(previous_notification2_y, | 535 EXPECT_EQ(previous_notification2_y, |
| 535 GetNotificationView(kNotificationId1)->bounds().y()); | 536 GetNotificationView(kNotificationId1)->bounds().y()); |
| 536 // The size should be kept. | 537 // The size should be kept. |
| 537 EXPECT_EQ(previous_height, GetMessageListView()->height()); | 538 EXPECT_EQ(previous_height, GetMessageListView()->height()); |
| 538 | 539 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 549 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()), | 550 (kMarginBetweenItems - MessageView::GetShadowInsets().bottom()), |
| 550 GetMessageListView()->height()); | 551 GetMessageListView()->height()); |
| 551 } | 552 } |
| 552 | 553 |
| 553 TEST_F(MessageCenterViewTest, CloseButton) { | 554 TEST_F(MessageCenterViewTest, CloseButton) { |
| 554 views::Button* close_button = GetButtonBar()->GetCloseAllButtonForTest(); | 555 views::Button* close_button = GetButtonBar()->GetCloseAllButtonForTest(); |
| 555 EXPECT_NE(nullptr, close_button); | 556 EXPECT_NE(nullptr, close_button); |
| 556 | 557 |
| 557 ((views::ButtonListener*)GetButtonBar()) | 558 ((views::ButtonListener*)GetButtonBar()) |
| 558 ->ButtonPressed(close_button, DummyEvent()); | 559 ->ButtonPressed(close_button, DummyEvent()); |
| 559 base::MessageLoop::current()->Run(); | 560 base::RunLoop().Run(); |
| 560 EXPECT_TRUE(GetMessageCenter()->remove_all_closable_notification_called_); | 561 EXPECT_TRUE(GetMessageCenter()->remove_all_closable_notification_called_); |
| 561 } | 562 } |
| 562 | 563 |
| 563 TEST_F(MessageCenterViewTest, CloseButtonEnablity) { | 564 TEST_F(MessageCenterViewTest, CloseButtonEnablity) { |
| 564 views::Button* close_button = GetButtonBar()->GetCloseAllButtonForTest(); | 565 views::Button* close_button = GetButtonBar()->GetCloseAllButtonForTest(); |
| 565 EXPECT_NE(nullptr, close_button); | 566 EXPECT_NE(nullptr, close_button); |
| 566 | 567 |
| 567 // There should be 2 non-pinned notifications. | 568 // There should be 2 non-pinned notifications. |
| 568 EXPECT_EQ(2u, GetMessageCenter()->GetVisibleNotifications().size()); | 569 EXPECT_EQ(2u, GetMessageCenter()->GetVisibleNotifications().size()); |
| 569 EXPECT_TRUE(close_button->enabled()); | 570 EXPECT_TRUE(close_button->enabled()); |
| 570 | 571 |
| 571 RemoveNotification(kNotificationId1, false); | 572 RemoveNotification(kNotificationId1, false); |
| 572 base::MessageLoop::current()->Run(); | 573 base::RunLoop().Run(); |
| 573 | 574 |
| 574 // There should be 1 non-pinned notification. | 575 // There should be 1 non-pinned notification. |
| 575 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); | 576 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size()); |
| 576 EXPECT_TRUE(close_button->enabled()); | 577 EXPECT_TRUE(close_button->enabled()); |
| 577 | 578 |
| 578 RemoveNotification(kNotificationId2, false); | 579 RemoveNotification(kNotificationId2, false); |
| 579 base::MessageLoop::current()->Run(); | 580 base::RunLoop().Run(); |
| 580 | 581 |
| 581 // There should be no notification. | 582 // There should be no notification. |
| 582 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size()); | 583 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size()); |
| 583 EXPECT_FALSE(close_button->enabled()); | 584 EXPECT_FALSE(close_button->enabled()); |
| 584 | 585 |
| 585 Notification normal_notification( | 586 Notification normal_notification( |
| 586 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), | 587 NOTIFICATION_TYPE_SIMPLE, std::string(kNotificationId1), |
| 587 base::UTF8ToUTF16("title2"), | 588 base::UTF8ToUTF16("title2"), |
| 588 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), | 589 base::UTF8ToUTF16("message\nwhich\nis\nvertically\nlong\n."), |
| 589 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), | 590 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 base::UTF8ToUTF16("message"), | 801 base::UTF8ToUTF16("message"), |
| 801 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), | 802 gfx::Image(), base::UTF8ToUTF16("display source"), GURL(), |
| 802 NotifierId(NotifierId::APPLICATION, "extension_id"), | 803 NotifierId(NotifierId::APPLICATION, "extension_id"), |
| 803 message_center::RichNotificationData(), NULL))); | 804 message_center::RichNotificationData(), NULL))); |
| 804 | 805 |
| 805 GetMessageCenterView()->SizeToPreferredSize(); | 806 GetMessageCenterView()->SizeToPreferredSize(); |
| 806 EXPECT_NE(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height()); | 807 EXPECT_NE(kEmptyMessageCenterViewHeight, GetMessageCenterView()->height()); |
| 807 } | 808 } |
| 808 | 809 |
| 809 } // namespace message_center | 810 } // namespace message_center |
| OLD | NEW |