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 #import "ui/message_center/cocoa/popup_collection.h" | 5 #import "ui/message_center/cocoa/popup_collection.h" |
6 | 6 |
7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 void AddThreeNotifications() { | 50 void AddThreeNotifications() { |
51 scoped_ptr<message_center::Notification> notification; | 51 scoped_ptr<message_center::Notification> notification; |
52 notification.reset(new message_center::Notification( | 52 notification.reset(new message_center::Notification( |
53 message_center::NOTIFICATION_TYPE_SIMPLE, | 53 message_center::NOTIFICATION_TYPE_SIMPLE, |
54 "1", | 54 "1", |
55 ASCIIToUTF16("One"), | 55 ASCIIToUTF16("One"), |
56 ASCIIToUTF16("This is the first notification to" | 56 ASCIIToUTF16("This is the first notification to" |
57 " be displayed"), | 57 " be displayed"), |
58 gfx::Image(), | 58 gfx::Image(), |
59 string16(), | 59 base::string16(), |
60 DummyNotifierId(), | 60 DummyNotifierId(), |
61 message_center::RichNotificationData(), | 61 message_center::RichNotificationData(), |
62 NULL)); | 62 NULL)); |
63 center_->AddNotification(notification.Pass()); | 63 center_->AddNotification(notification.Pass()); |
64 | 64 |
65 notification.reset(new message_center::Notification( | 65 notification.reset(new message_center::Notification( |
66 message_center::NOTIFICATION_TYPE_SIMPLE, | 66 message_center::NOTIFICATION_TYPE_SIMPLE, |
67 "2", | 67 "2", |
68 ASCIIToUTF16("Two"), | 68 ASCIIToUTF16("Two"), |
69 ASCIIToUTF16("This is the second notification."), | 69 ASCIIToUTF16("This is the second notification."), |
70 gfx::Image(), | 70 gfx::Image(), |
71 string16(), | 71 base::string16(), |
72 DummyNotifierId(), | 72 DummyNotifierId(), |
73 message_center::RichNotificationData(), | 73 message_center::RichNotificationData(), |
74 NULL)); | 74 NULL)); |
75 center_->AddNotification(notification.Pass()); | 75 center_->AddNotification(notification.Pass()); |
76 | 76 |
77 notification.reset(new message_center::Notification( | 77 notification.reset(new message_center::Notification( |
78 message_center::NOTIFICATION_TYPE_SIMPLE, | 78 message_center::NOTIFICATION_TYPE_SIMPLE, |
79 "3", | 79 "3", |
80 ASCIIToUTF16("Three"), | 80 ASCIIToUTF16("Three"), |
81 ASCIIToUTF16("This is the third notification " | 81 ASCIIToUTF16("This is the third notification " |
82 "that has a much longer body " | 82 "that has a much longer body " |
83 "than the other notifications. It " | 83 "than the other notifications. It " |
84 "may not fit on the screen if we " | 84 "may not fit on the screen if we " |
85 "set the screen size too small or " | 85 "set the screen size too small or " |
86 "if the notification is way too big"), | 86 "if the notification is way too big"), |
87 gfx::Image(), | 87 gfx::Image(), |
88 string16(), | 88 base::string16(), |
89 DummyNotifierId(), | 89 DummyNotifierId(), |
90 message_center::RichNotificationData(), | 90 message_center::RichNotificationData(), |
91 NULL)); | 91 NULL)); |
92 center_->AddNotification(notification.Pass()); | 92 center_->AddNotification(notification.Pass()); |
93 WaitForAnimationEnded(); | 93 WaitForAnimationEnded(); |
94 } | 94 } |
95 | 95 |
96 bool CheckSpacingBetween(MCPopupController* upper, MCPopupController* lower) { | 96 bool CheckSpacingBetween(MCPopupController* upper, MCPopupController* lower) { |
97 CGFloat minY = NSMinY([[upper window] frame]); | 97 CGFloat minY = NSMinY([[upper window] frame]); |
98 CGFloat maxY = NSMaxY([[lower window] frame]); | 98 CGFloat maxY = NSMaxY([[lower window] frame]); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 EXPECT_EQ(2u, [[collection_ popups] count]); // "3" does not fit on screen. | 133 EXPECT_EQ(2u, [[collection_ popups] count]); // "3" does not fit on screen. |
134 | 134 |
135 scoped_ptr<message_center::Notification> notification; | 135 scoped_ptr<message_center::Notification> notification; |
136 | 136 |
137 notification.reset(new message_center::Notification( | 137 notification.reset(new message_center::Notification( |
138 message_center::NOTIFICATION_TYPE_SIMPLE, | 138 message_center::NOTIFICATION_TYPE_SIMPLE, |
139 "4", | 139 "4", |
140 ASCIIToUTF16("Four"), | 140 ASCIIToUTF16("Four"), |
141 ASCIIToUTF16("This is the fourth notification."), | 141 ASCIIToUTF16("This is the fourth notification."), |
142 gfx::Image(), | 142 gfx::Image(), |
143 string16(), | 143 base::string16(), |
144 DummyNotifierId(), | 144 DummyNotifierId(), |
145 message_center::RichNotificationData(), | 145 message_center::RichNotificationData(), |
146 NULL)); | 146 NULL)); |
147 center_->AddNotification(notification.Pass()); | 147 center_->AddNotification(notification.Pass()); |
148 WaitForAnimationEnded(); | 148 WaitForAnimationEnded(); |
149 | 149 |
150 // Remove "1" and "3" should fit on screen. | 150 // Remove "1" and "3" should fit on screen. |
151 center_->RemoveNotification("1", true); | 151 center_->RemoveNotification("1", true); |
152 WaitForAnimationEnded(); | 152 WaitForAnimationEnded(); |
153 ASSERT_EQ(2u, [[collection_ popups] count]); | 153 ASSERT_EQ(2u, [[collection_ popups] count]); |
(...skipping 28 matching lines...) Expand all Loading... |
182 // Set priority so that kMaxVisiblePopupNotifications does not hide it. | 182 // Set priority so that kMaxVisiblePopupNotifications does not hide it. |
183 message_center::RichNotificationData optional; | 183 message_center::RichNotificationData optional; |
184 optional.priority = message_center::HIGH_PRIORITY; | 184 optional.priority = message_center::HIGH_PRIORITY; |
185 scoped_ptr<message_center::Notification> notification; | 185 scoped_ptr<message_center::Notification> notification; |
186 notification.reset(new message_center::Notification( | 186 notification.reset(new message_center::Notification( |
187 message_center::NOTIFICATION_TYPE_SIMPLE, | 187 message_center::NOTIFICATION_TYPE_SIMPLE, |
188 "4", | 188 "4", |
189 ASCIIToUTF16("Four"), | 189 ASCIIToUTF16("Four"), |
190 ASCIIToUTF16("This is the fourth notification."), | 190 ASCIIToUTF16("This is the fourth notification."), |
191 gfx::Image(), | 191 gfx::Image(), |
192 string16(), | 192 base::string16(), |
193 DummyNotifierId(), | 193 DummyNotifierId(), |
194 optional, | 194 optional, |
195 NULL)); | 195 NULL)); |
196 center_->AddNotification(notification.Pass()); | 196 center_->AddNotification(notification.Pass()); |
197 WaitForAnimationEnded(); | 197 WaitForAnimationEnded(); |
198 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:2], | 198 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:2], |
199 [popups objectAtIndex:3])); | 199 [popups objectAtIndex:3])); |
200 | 200 |
201 // Remove "2". | 201 // Remove "2". |
202 center_->RemoveNotification("2", true); | 202 center_->RemoveNotification("2", true); |
(...skipping 17 matching lines...) Expand all Loading... |
220 | 220 |
221 EXPECT_EQ(0u, [[collection_ popups] count]); | 221 EXPECT_EQ(0u, [[collection_ popups] count]); |
222 scoped_ptr<message_center::Notification> notification; | 222 scoped_ptr<message_center::Notification> notification; |
223 notification.reset(new message_center::Notification( | 223 notification.reset(new message_center::Notification( |
224 message_center::NOTIFICATION_TYPE_SIMPLE, | 224 message_center::NOTIFICATION_TYPE_SIMPLE, |
225 "1", | 225 "1", |
226 ASCIIToUTF16("One"), | 226 ASCIIToUTF16("One"), |
227 ASCIIToUTF16("This is the first notification to" | 227 ASCIIToUTF16("This is the first notification to" |
228 " be displayed"), | 228 " be displayed"), |
229 gfx::Image(), | 229 gfx::Image(), |
230 string16(), | 230 base::string16(), |
231 DummyNotifierId(), | 231 DummyNotifierId(), |
232 message_center::RichNotificationData(), | 232 message_center::RichNotificationData(), |
233 NULL)); | 233 NULL)); |
234 center_->AddNotification(notification.Pass()); | 234 center_->AddNotification(notification.Pass()); |
235 WaitForAnimationEnded(); | 235 WaitForAnimationEnded(); |
236 EXPECT_EQ(1u, [[collection_ popups] count]); | 236 EXPECT_EQ(1u, [[collection_ popups] count]); |
237 | 237 |
238 // Now give the notification a longer message so that it no longer fits. | 238 // Now give the notification a longer message so that it no longer fits. |
239 notification.reset(new message_center::Notification( | 239 notification.reset(new message_center::Notification( |
240 message_center::NOTIFICATION_TYPE_SIMPLE, | 240 message_center::NOTIFICATION_TYPE_SIMPLE, |
241 "1", | 241 "1", |
242 ASCIIToUTF16("One"), | 242 ASCIIToUTF16("One"), |
243 ASCIIToUTF16("This is now a very very very very " | 243 ASCIIToUTF16("This is now a very very very very " |
244 "very very very very very very very " | 244 "very very very very very very very " |
245 "very very very very very very very " | 245 "very very very very very very very " |
246 "very very very very very very very " | 246 "very very very very very very very " |
247 "very very very very very very very " | 247 "very very very very very very very " |
248 "very very very very very very very " | 248 "very very very very very very very " |
249 "very very very very very very very " | 249 "very very very very very very very " |
250 "long notification."), | 250 "long notification."), |
251 gfx::Image(), | 251 gfx::Image(), |
252 string16(), | 252 base::string16(), |
253 DummyNotifierId(), | 253 DummyNotifierId(), |
254 message_center::RichNotificationData(), | 254 message_center::RichNotificationData(), |
255 NULL)); | 255 NULL)); |
256 center_->UpdateNotification("1", notification.Pass()); | 256 center_->UpdateNotification("1", notification.Pass()); |
257 WaitForAnimationEnded(); | 257 WaitForAnimationEnded(); |
258 EXPECT_EQ(0u, [[collection_ popups] count]); | 258 EXPECT_EQ(0u, [[collection_ popups] count]); |
259 } | 259 } |
260 | 260 |
261 TEST_F(PopupCollectionTest, UpdateIconAndBody) { | 261 TEST_F(PopupCollectionTest, UpdateIconAndBody) { |
262 AddThreeNotifications(); | 262 AddThreeNotifications(); |
(...skipping 23 matching lines...) Expand all Loading... |
286 notification.reset(new message_center::Notification( | 286 notification.reset(new message_center::Notification( |
287 message_center::NOTIFICATION_TYPE_SIMPLE, | 287 message_center::NOTIFICATION_TYPE_SIMPLE, |
288 "1", | 288 "1", |
289 ASCIIToUTF16("One is going to get a much longer " | 289 ASCIIToUTF16("One is going to get a much longer " |
290 "title than it previously had."), | 290 "title than it previously had."), |
291 ASCIIToUTF16("This is the first notification to " | 291 ASCIIToUTF16("This is the first notification to " |
292 "be displayed, but it will also be " | 292 "be displayed, but it will also be " |
293 "updated to have a significantly " | 293 "updated to have a significantly " |
294 "longer body"), | 294 "longer body"), |
295 gfx::Image(), | 295 gfx::Image(), |
296 string16(), | 296 base::string16(), |
297 DummyNotifierId(), | 297 DummyNotifierId(), |
298 message_center::RichNotificationData(), | 298 message_center::RichNotificationData(), |
299 NULL)); | 299 NULL)); |
300 center_->AddNotification(notification.Pass()); | 300 center_->AddNotification(notification.Pass()); |
301 WaitForAnimationEnded(); | 301 WaitForAnimationEnded(); |
302 EXPECT_GT(NSHeight([[controller view] frame]), NSHeight(old_frame)); | 302 EXPECT_GT(NSHeight([[controller view] frame]), NSHeight(old_frame)); |
303 | 303 |
304 // Test updated spacing. | 304 // Test updated spacing. |
305 EXPECT_EQ(3u, [popups count]); | 305 EXPECT_EQ(3u, [popups count]); |
306 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0], | 306 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:0], |
307 [popups objectAtIndex:1])); | 307 [popups objectAtIndex:1])); |
308 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1], | 308 EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:1], |
309 [popups objectAtIndex:2])); | 309 [popups objectAtIndex:2])); |
310 EXPECT_EQ("1", [[popups objectAtIndex:0] notificationID]); | 310 EXPECT_EQ("1", [[popups objectAtIndex:0] notificationID]); |
311 EXPECT_EQ("2", [[popups objectAtIndex:1] notificationID]); | 311 EXPECT_EQ("2", [[popups objectAtIndex:1] notificationID]); |
312 EXPECT_EQ("3", [[popups objectAtIndex:2] notificationID]); | 312 EXPECT_EQ("3", [[popups objectAtIndex:2] notificationID]); |
313 } | 313 } |
314 | 314 |
315 TEST_F(PopupCollectionTest, CloseCollectionBeforeNewPopupAnimationEnds) { | 315 TEST_F(PopupCollectionTest, CloseCollectionBeforeNewPopupAnimationEnds) { |
316 // Add a notification and don't wait for the animation to finish. | 316 // Add a notification and don't wait for the animation to finish. |
317 scoped_ptr<message_center::Notification> notification; | 317 scoped_ptr<message_center::Notification> notification; |
318 notification.reset(new message_center::Notification( | 318 notification.reset(new message_center::Notification( |
319 message_center::NOTIFICATION_TYPE_SIMPLE, | 319 message_center::NOTIFICATION_TYPE_SIMPLE, |
320 "1", | 320 "1", |
321 ASCIIToUTF16("One"), | 321 ASCIIToUTF16("One"), |
322 ASCIIToUTF16("This is the first notification to" | 322 ASCIIToUTF16("This is the first notification to" |
323 " be displayed"), | 323 " be displayed"), |
324 gfx::Image(), | 324 gfx::Image(), |
325 string16(), | 325 base::string16(), |
326 DummyNotifierId(), | 326 DummyNotifierId(), |
327 message_center::RichNotificationData(), | 327 message_center::RichNotificationData(), |
328 NULL)); | 328 NULL)); |
329 center_->AddNotification(notification.Pass()); | 329 center_->AddNotification(notification.Pass()); |
330 | 330 |
331 // Release the popup collection before the animation ends. No crash should | 331 // Release the popup collection before the animation ends. No crash should |
332 // be expected. | 332 // be expected. |
333 collection_.reset(); | 333 collection_.reset(); |
334 } | 334 } |
335 | 335 |
(...skipping 12 matching lines...) Expand all Loading... |
348 AddThreeNotifications(); | 348 AddThreeNotifications(); |
349 | 349 |
350 // Update a notification and don't wait for the animation to finish. | 350 // Update a notification and don't wait for the animation to finish. |
351 scoped_ptr<message_center::Notification> notification; | 351 scoped_ptr<message_center::Notification> notification; |
352 notification.reset(new message_center::Notification( | 352 notification.reset(new message_center::Notification( |
353 message_center::NOTIFICATION_TYPE_SIMPLE, | 353 message_center::NOTIFICATION_TYPE_SIMPLE, |
354 "1", | 354 "1", |
355 ASCIIToUTF16("One"), | 355 ASCIIToUTF16("One"), |
356 ASCIIToUTF16("New message."), | 356 ASCIIToUTF16("New message."), |
357 gfx::Image(), | 357 gfx::Image(), |
358 string16(), | 358 base::string16(), |
359 DummyNotifierId(), | 359 DummyNotifierId(), |
360 message_center::RichNotificationData(), | 360 message_center::RichNotificationData(), |
361 NULL)); | 361 NULL)); |
362 center_->UpdateNotification("1", notification.Pass()); | 362 center_->UpdateNotification("1", notification.Pass()); |
363 | 363 |
364 // Release the popup collection before the animation ends. No crash should | 364 // Release the popup collection before the animation ends. No crash should |
365 // be expected. | 365 // be expected. |
366 collection_.reset(); | 366 collection_.reset(); |
367 } | 367 } |
368 | 368 |
369 } // namespace message_center | 369 } // namespace message_center |
OLD | NEW |