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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 collection_->toasts_.begin(); | 91 collection_->toasts_.begin(); |
92 iter != collection_->toasts_.end(); ++iter) { | 92 iter != collection_->toasts_.end(); ++iter) { |
93 if ((*iter)->id() == id) | 93 if ((*iter)->id() == id) |
94 return *iter; | 94 return *iter; |
95 } | 95 } |
96 return NULL; | 96 return NULL; |
97 } | 97 } |
98 | 98 |
99 std::string AddNotification() { | 99 std::string AddNotification() { |
100 std::string id = base::IntToString(id_++); | 100 std::string id = base::IntToString(id_++); |
101 scoped_ptr<Notification> notification(new Notification( | 101 std::unique_ptr<Notification> notification(new Notification( |
102 NOTIFICATION_TYPE_BASE_FORMAT, id, base::UTF8ToUTF16("test title"), | 102 NOTIFICATION_TYPE_BASE_FORMAT, id, base::UTF8ToUTF16("test title"), |
103 base::UTF8ToUTF16("test message"), gfx::Image(), | 103 base::UTF8ToUTF16("test message"), gfx::Image(), |
104 base::string16() /* display_source */, GURL(), NotifierId(), | 104 base::string16() /* display_source */, GURL(), NotifierId(), |
105 message_center::RichNotificationData(), new NotificationDelegate())); | 105 message_center::RichNotificationData(), new NotificationDelegate())); |
106 MessageCenter::Get()->AddNotification(std::move(notification)); | 106 MessageCenter::Get()->AddNotification(std::move(notification)); |
107 return id; | 107 return id; |
108 } | 108 } |
109 | 109 |
110 void PrepareForWait() { collection_->CreateRunLoopForTest(); } | 110 void PrepareForWait() { collection_->CreateRunLoopForTest(); } |
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( | 121 MessageCenter::Get()->RemoveAllNotifications( |
122 false /* by_user */, MessageCenter::RemoveType::ALL); | 122 false /* by_user */, MessageCenter::RemoveType::ALL); |
123 } | 123 } |
124 | 124 |
125 gfx::Rect GetToastRectAt(size_t index) { | 125 gfx::Rect GetToastRectAt(size_t index) { |
126 return collection_->GetToastRectAt(index); | 126 return collection_->GetToastRectAt(index); |
127 } | 127 } |
128 | 128 |
129 private: | 129 private: |
130 scoped_ptr<MessagePopupCollection> collection_; | 130 std::unique_ptr<MessagePopupCollection> collection_; |
131 scoped_ptr<DesktopPopupAlignmentDelegate> alignment_delegate_; | 131 std::unique_ptr<DesktopPopupAlignmentDelegate> alignment_delegate_; |
132 int id_; | 132 int id_; |
133 }; | 133 }; |
134 | 134 |
135 #if defined(OS_CHROMEOS) | 135 #if defined(OS_CHROMEOS) |
136 TEST_F(MessagePopupCollectionTest, DismissOnClick) { | 136 TEST_F(MessagePopupCollectionTest, DismissOnClick) { |
137 | 137 |
138 std::string id1 = AddNotification(); | 138 std::string id1 = AddNotification(); |
139 std::string id2 = AddNotification(); | 139 std::string id2 = AddNotification(); |
140 WaitForTransitionsDone(); | 140 WaitForTransitionsDone(); |
141 | 141 |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 | 479 |
480 CloseAllToasts(); | 480 CloseAllToasts(); |
481 WaitForTransitionsDone(); | 481 WaitForTransitionsDone(); |
482 } | 482 } |
483 | 483 |
484 #if defined(OS_CHROMEOS) | 484 #if defined(OS_CHROMEOS) |
485 | 485 |
486 TEST_F(MessagePopupCollectionTest, CloseNonClosableNotifications) { | 486 TEST_F(MessagePopupCollectionTest, CloseNonClosableNotifications) { |
487 const char* kNotificationId = "NOTIFICATION1"; | 487 const char* kNotificationId = "NOTIFICATION1"; |
488 | 488 |
489 scoped_ptr<Notification> notification(new Notification( | 489 std::unique_ptr<Notification> notification(new Notification( |
490 NOTIFICATION_TYPE_BASE_FORMAT, kNotificationId, | 490 NOTIFICATION_TYPE_BASE_FORMAT, kNotificationId, |
491 base::UTF8ToUTF16("test title"), base::UTF8ToUTF16("test message"), | 491 base::UTF8ToUTF16("test title"), base::UTF8ToUTF16("test message"), |
492 gfx::Image(), base::string16() /* display_source */, GURL(), | 492 gfx::Image(), base::string16() /* display_source */, GURL(), |
493 NotifierId(NotifierId::APPLICATION, kNotificationId), | 493 NotifierId(NotifierId::APPLICATION, kNotificationId), |
494 message_center::RichNotificationData(), new NotificationDelegate())); | 494 message_center::RichNotificationData(), new NotificationDelegate())); |
495 notification->set_pinned(true); | 495 notification->set_pinned(true); |
496 | 496 |
497 // Add a pinned notification. | 497 // Add a pinned notification. |
498 MessageCenter::Get()->AddNotification(std::move(notification)); | 498 MessageCenter::Get()->AddNotification(std::move(notification)); |
499 WaitForTransitionsDone(); | 499 WaitForTransitionsDone(); |
(...skipping 15 matching lines...) Expand all Loading... |
515 // Confirms that there is no toast. | 515 // Confirms that there is no toast. |
516 EXPECT_EQ(0u, GetToastCounts()); | 516 EXPECT_EQ(0u, GetToastCounts()); |
517 // But the notification still exists. | 517 // But the notification still exists. |
518 EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); | 518 EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
519 } | 519 } |
520 | 520 |
521 #endif // defined(OS_CHROMEOS) | 521 #endif // defined(OS_CHROMEOS) |
522 | 522 |
523 } // namespace test | 523 } // namespace test |
524 } // namespace message_center | 524 } // namespace message_center |
OLD | NEW |