| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_popup_collection.h" | 5 #include "ui/message_center/views/message_popup_collection.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 // Assumes there is non-zero pending work. | 112 // Assumes there is non-zero pending work. |
| 113 void WaitForTransitionsDone() { | 113 void WaitForTransitionsDone() { |
| 114 collection_->WaitForTest(); | 114 collection_->WaitForTest(); |
| 115 collection_->CreateRunLoopForTest(); | 115 collection_->CreateRunLoopForTest(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void CloseAllToasts() { | 118 void CloseAllToasts() { |
| 119 // Assumes there is at least one toast to close. | 119 // Assumes there is at least one toast to close. |
| 120 EXPECT_TRUE(GetToastCounts() > 0); | 120 EXPECT_TRUE(GetToastCounts() > 0); |
| 121 MessageCenter::Get()->RemoveAllNotifications(false); | 121 MessageCenter::Get()->RemoveAllNotifications( |
| 122 false /* by_user */, MessageCenter::RemoveType::ALL); |
| 122 } | 123 } |
| 123 | 124 |
| 124 gfx::Rect GetToastRectAt(size_t index) { | 125 gfx::Rect GetToastRectAt(size_t index) { |
| 125 return collection_->GetToastRectAt(index); | 126 return collection_->GetToastRectAt(index); |
| 126 } | 127 } |
| 127 | 128 |
| 128 private: | 129 private: |
| 129 scoped_ptr<MessagePopupCollection> collection_; | 130 scoped_ptr<MessagePopupCollection> collection_; |
| 130 scoped_ptr<DesktopPopupAlignmentDelegate> alignment_delegate_; | 131 scoped_ptr<DesktopPopupAlignmentDelegate> alignment_delegate_; |
| 131 int id_; | 132 int id_; |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 | 474 |
| 474 for (size_t i = 0; i < notifications_to_add - 1; ++i) { | 475 for (size_t i = 0; i < notifications_to_add - 1; ++i) { |
| 475 EXPECT_TRUE(IsToastShown(ids[i])) << "Should show the " << i << "th ID"; | 476 EXPECT_TRUE(IsToastShown(ids[i])) << "Should show the " << i << "th ID"; |
| 476 } | 477 } |
| 477 EXPECT_FALSE(IsToastShown(ids[notifications_to_add - 1])); | 478 EXPECT_FALSE(IsToastShown(ids[notifications_to_add - 1])); |
| 478 | 479 |
| 479 CloseAllToasts(); | 480 CloseAllToasts(); |
| 480 WaitForTransitionsDone(); | 481 WaitForTransitionsDone(); |
| 481 } | 482 } |
| 482 | 483 |
| 484 #if defined(OS_CHROMEOS) |
| 485 |
| 486 TEST_F(MessagePopupCollectionTest, CloseNonClosableNotifications) { |
| 487 const char* kNotificationId = "NOTIFICATION1"; |
| 488 |
| 489 scoped_ptr<Notification> notification(new Notification( |
| 490 NOTIFICATION_TYPE_BASE_FORMAT, kNotificationId, |
| 491 base::UTF8ToUTF16("test title"), base::UTF8ToUTF16("test message"), |
| 492 gfx::Image(), base::string16() /* display_source */, GURL(), |
| 493 NotifierId(NotifierId::APPLICATION, kNotificationId), |
| 494 message_center::RichNotificationData(), new NotificationDelegate())); |
| 495 notification->set_pinned(true); |
| 496 |
| 497 // Add a pinned notification. |
| 498 MessageCenter::Get()->AddNotification(std::move(notification)); |
| 499 WaitForTransitionsDone(); |
| 500 |
| 501 // Confirms that there is a toast. |
| 502 EXPECT_EQ(1u, GetToastCounts()); |
| 503 EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 504 |
| 505 // Close the toast. |
| 506 views::WidgetDelegateView* toast1 = GetToast(kNotificationId); |
| 507 ASSERT_TRUE(toast1 != NULL); |
| 508 ui::MouseEvent event(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), |
| 509 ui::EventTimeForNow(), 0, 0); |
| 510 toast1->OnMouseEntered(event); |
| 511 static_cast<MessageCenterObserver*>(collection()) |
| 512 ->OnNotificationRemoved(kNotificationId, true); |
| 513 WaitForTransitionsDone(); |
| 514 |
| 515 // Confirms that there is no toast. |
| 516 EXPECT_EQ(0u, GetToastCounts()); |
| 517 // But the notification still exists. |
| 518 EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 519 } |
| 520 |
| 521 #endif // defined(OS_CHROMEOS) |
| 483 | 522 |
| 484 } // namespace test | 523 } // namespace test |
| 485 } // namespace message_center | 524 } // namespace message_center |
| OLD | NEW |