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/notification_controller.h" | 5 #import "ui/message_center/cocoa/notification_controller.h" |
6 | 6 |
7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 110 |
111 protected: | 111 protected: |
112 message_center::NotifierId DummyNotifierId() { | 112 message_center::NotifierId DummyNotifierId() { |
113 return message_center::NotifierId(); | 113 return message_center::NotifierId(); |
114 } | 114 } |
115 }; | 115 }; |
116 | 116 |
117 TEST_F(NotificationControllerTest, BasicLayout) { | 117 TEST_F(NotificationControllerTest, BasicLayout) { |
118 scoped_ptr<message_center::Notification> notification( | 118 scoped_ptr<message_center::Notification> notification( |
119 new message_center::Notification( | 119 new message_center::Notification( |
120 message_center::NOTIFICATION_TYPE_SIMPLE, | 120 message_center::NOTIFICATION_TYPE_SIMPLE, "", |
121 "", | |
122 ASCIIToUTF16("Added to circles"), | 121 ASCIIToUTF16("Added to circles"), |
123 ASCIIToUTF16("Jonathan and 5 others"), | 122 ASCIIToUTF16("Jonathan and 5 others"), gfx::Image(), base::string16(), |
124 gfx::Image(), | 123 GURL(), DummyNotifierId(), message_center::RichNotificationData(), |
125 base::string16(), | |
126 DummyNotifierId(), | |
127 message_center::RichNotificationData(), | |
128 NULL)); | 124 NULL)); |
129 gfx::Image testIcon([TestIcon() retain]); | 125 gfx::Image testIcon([TestIcon() retain]); |
130 notification->set_icon(testIcon); | 126 notification->set_icon(testIcon); |
131 notification->set_small_image(testIcon); | 127 notification->set_small_image(testIcon); |
132 | 128 |
133 base::scoped_nsobject<MCNotificationController> controller( | 129 base::scoped_nsobject<MCNotificationController> controller( |
134 [[MCNotificationController alloc] initWithNotification:notification.get() | 130 [[MCNotificationController alloc] initWithNotification:notification.get() |
135 messageCenter:NULL]); | 131 messageCenter:NULL]); |
136 [controller view]; | 132 [controller view]; |
137 | 133 |
138 EXPECT_EQ(TestIcon(), [[controller iconView] image]); | 134 EXPECT_EQ(TestIcon(), [[controller iconView] image]); |
139 EXPECT_EQ(TestIcon(), [[controller smallImageView] image]); | 135 EXPECT_EQ(TestIcon(), [[controller smallImageView] image]); |
140 EXPECT_EQ(base::SysNSStringToUTF16([[controller titleView] string]), | 136 EXPECT_EQ(base::SysNSStringToUTF16([[controller titleView] string]), |
141 notification->title()); | 137 notification->title()); |
142 EXPECT_EQ(base::SysNSStringToUTF16([[controller messageView] string]), | 138 EXPECT_EQ(base::SysNSStringToUTF16([[controller messageView] string]), |
143 notification->message()); | 139 notification->message()); |
144 EXPECT_EQ(controller.get(), [[controller closeButton] target]); | 140 EXPECT_EQ(controller.get(), [[controller closeButton] target]); |
145 } | 141 } |
146 | 142 |
147 TEST_F(NotificationControllerTest, OverflowText) { | 143 TEST_F(NotificationControllerTest, OverflowText) { |
148 scoped_ptr<message_center::Notification> notification( | 144 scoped_ptr<message_center::Notification> notification( |
149 new message_center::Notification( | 145 new message_center::Notification( |
150 message_center::NOTIFICATION_TYPE_SIMPLE, | 146 message_center::NOTIFICATION_TYPE_SIMPLE, "", |
151 "", | |
152 ASCIIToUTF16("This is a much longer title that should wrap " | 147 ASCIIToUTF16("This is a much longer title that should wrap " |
153 "multiple lines."), | 148 "multiple lines."), |
154 ASCIIToUTF16("And even the message is long. This sure is a wordy " | 149 ASCIIToUTF16("And even the message is long. This sure is a wordy " |
155 "notification. Are you really going to read this " | 150 "notification. Are you really going to read this " |
156 "entire thing?"), | 151 "entire thing?"), |
157 gfx::Image(), | 152 gfx::Image(), base::string16(), GURL(), DummyNotifierId(), |
158 base::string16(), | 153 message_center::RichNotificationData(), NULL)); |
159 DummyNotifierId(), | |
160 message_center::RichNotificationData(), | |
161 NULL)); | |
162 base::scoped_nsobject<MCNotificationController> controller( | 154 base::scoped_nsobject<MCNotificationController> controller( |
163 [[MCNotificationController alloc] initWithNotification:notification.get() | 155 [[MCNotificationController alloc] initWithNotification:notification.get() |
164 messageCenter:NULL]); | 156 messageCenter:NULL]); |
165 [controller view]; | 157 [controller view]; |
166 | 158 |
167 EXPECT_GT(NSHeight([[controller view] frame]), | 159 EXPECT_GT(NSHeight([[controller view] frame]), |
168 message_center::kNotificationIconSize); | 160 message_center::kNotificationIconSize); |
169 } | 161 } |
170 | 162 |
171 TEST_F(NotificationControllerTest, Close) { | 163 TEST_F(NotificationControllerTest, Close) { |
172 scoped_ptr<message_center::Notification> notification( | 164 scoped_ptr<message_center::Notification> notification( |
173 new message_center::Notification( | 165 new message_center::Notification( |
174 message_center::NOTIFICATION_TYPE_SIMPLE, | 166 message_center::NOTIFICATION_TYPE_SIMPLE, "an_id", base::string16(), |
175 "an_id", | 167 base::string16(), gfx::Image(), base::string16(), GURL(), |
176 base::string16(), | 168 DummyNotifierId(), message_center::RichNotificationData(), NULL)); |
177 base::string16(), | |
178 gfx::Image(), | |
179 base::string16(), | |
180 DummyNotifierId(), | |
181 message_center::RichNotificationData(), | |
182 NULL)); | |
183 MockMessageCenter message_center; | 169 MockMessageCenter message_center; |
184 | 170 |
185 base::scoped_nsobject<MCNotificationController> controller( | 171 base::scoped_nsobject<MCNotificationController> controller( |
186 [[MCNotificationController alloc] initWithNotification:notification.get() | 172 [[MCNotificationController alloc] initWithNotification:notification.get() |
187 messageCenter:&message_center]); | 173 messageCenter:&message_center]); |
188 [controller view]; | 174 [controller view]; |
189 | 175 |
190 [[controller closeButton] performClick:nil]; | 176 [[controller closeButton] performClick:nil]; |
191 | 177 |
192 EXPECT_EQ(1, message_center.remove_count()); | 178 EXPECT_EQ(1, message_center.remove_count()); |
193 EXPECT_EQ("an_id", message_center.last_removed_id()); | 179 EXPECT_EQ("an_id", message_center.last_removed_id()); |
194 EXPECT_TRUE(message_center.last_removed_by_user()); | 180 EXPECT_TRUE(message_center.last_removed_by_user()); |
195 } | 181 } |
196 | 182 |
197 TEST_F(NotificationControllerTest, Update) { | 183 TEST_F(NotificationControllerTest, Update) { |
198 scoped_ptr<message_center::Notification> notification( | 184 scoped_ptr<message_center::Notification> notification( |
199 new message_center::Notification( | 185 new message_center::Notification( |
200 message_center::NOTIFICATION_TYPE_SIMPLE, | 186 message_center::NOTIFICATION_TYPE_SIMPLE, "", |
201 "", | |
202 ASCIIToUTF16("A simple title"), | 187 ASCIIToUTF16("A simple title"), |
203 ASCIIToUTF16("This message isn't too long and should fit in the" | 188 ASCIIToUTF16("This message isn't too long and should fit in the" |
204 "default bounds."), | 189 "default bounds."), |
205 gfx::Image(), | 190 gfx::Image(), base::string16(), GURL(), DummyNotifierId(), |
206 base::string16(), | 191 message_center::RichNotificationData(), NULL)); |
207 DummyNotifierId(), | |
208 message_center::RichNotificationData(), | |
209 NULL)); | |
210 base::scoped_nsobject<MCNotificationController> controller( | 192 base::scoped_nsobject<MCNotificationController> controller( |
211 [[MCNotificationController alloc] initWithNotification:notification.get() | 193 [[MCNotificationController alloc] initWithNotification:notification.get() |
212 messageCenter:NULL]); | 194 messageCenter:NULL]); |
213 | 195 |
214 // Set up the default layout. | 196 // Set up the default layout. |
215 [controller view]; | 197 [controller view]; |
216 EXPECT_EQ(NSHeight([[controller view] frame]), | 198 EXPECT_EQ(NSHeight([[controller view] frame]), |
217 message_center::kNotificationIconSize); | 199 message_center::kNotificationIconSize); |
218 EXPECT_FALSE([[controller iconView] image]); | 200 EXPECT_FALSE([[controller iconView] image]); |
219 EXPECT_FALSE([[controller smallImageView] image]); | 201 EXPECT_FALSE([[controller smallImageView] image]); |
(...skipping 11 matching lines...) Expand all Loading... |
231 | 213 |
232 TEST_F(NotificationControllerTest, Buttons) { | 214 TEST_F(NotificationControllerTest, Buttons) { |
233 message_center::RichNotificationData optional; | 215 message_center::RichNotificationData optional; |
234 message_center::ButtonInfo button1(UTF8ToUTF16("button1")); | 216 message_center::ButtonInfo button1(UTF8ToUTF16("button1")); |
235 optional.buttons.push_back(button1); | 217 optional.buttons.push_back(button1); |
236 message_center::ButtonInfo button2(UTF8ToUTF16("button2")); | 218 message_center::ButtonInfo button2(UTF8ToUTF16("button2")); |
237 optional.buttons.push_back(button2); | 219 optional.buttons.push_back(button2); |
238 | 220 |
239 scoped_ptr<message_center::Notification> notification( | 221 scoped_ptr<message_center::Notification> notification( |
240 new message_center::Notification( | 222 new message_center::Notification( |
241 message_center::NOTIFICATION_TYPE_BASE_FORMAT, | 223 message_center::NOTIFICATION_TYPE_BASE_FORMAT, "an_id", |
242 "an_id", | 224 base::string16(), base::string16(), gfx::Image(), base::string16(), |
243 base::string16(), | 225 GURL(), DummyNotifierId(), optional, NULL)); |
244 base::string16(), | |
245 gfx::Image(), | |
246 base::string16(), | |
247 DummyNotifierId(), | |
248 optional, | |
249 NULL)); | |
250 MockMessageCenter message_center; | 226 MockMessageCenter message_center; |
251 | 227 |
252 base::scoped_nsobject<MCNotificationController> controller( | 228 base::scoped_nsobject<MCNotificationController> controller( |
253 [[MCNotificationController alloc] initWithNotification:notification.get() | 229 [[MCNotificationController alloc] initWithNotification:notification.get() |
254 messageCenter:&message_center]); | 230 messageCenter:&message_center]); |
255 [controller view]; | 231 [controller view]; |
256 | 232 |
257 [[controller secondButton] performClick:nil]; | 233 [[controller secondButton] performClick:nil]; |
258 | 234 |
259 EXPECT_EQ("an_id", message_center.last_clicked_id()); | 235 EXPECT_EQ("an_id", message_center.last_clicked_id()); |
260 EXPECT_EQ(1, message_center.last_clicked_index()); | 236 EXPECT_EQ(1, message_center.last_clicked_index()); |
261 } | 237 } |
262 | 238 |
263 TEST_F(NotificationControllerTest, Image) { | 239 TEST_F(NotificationControllerTest, Image) { |
264 scoped_ptr<message_center::Notification> notification( | 240 scoped_ptr<message_center::Notification> notification( |
265 new message_center::Notification( | 241 new message_center::Notification( |
266 message_center::NOTIFICATION_TYPE_BASE_FORMAT, | 242 message_center::NOTIFICATION_TYPE_BASE_FORMAT, "an_id", |
267 "an_id", | 243 base::string16(), base::string16(), gfx::Image(), base::string16(), |
268 base::string16(), | 244 GURL(), DummyNotifierId(), message_center::RichNotificationData(), |
269 base::string16(), | |
270 gfx::Image(), | |
271 base::string16(), | |
272 DummyNotifierId(), | |
273 message_center::RichNotificationData(), | |
274 NULL)); | 245 NULL)); |
275 NSImage* image = [NSImage imageNamed:NSImageNameFolder]; | 246 NSImage* image = [NSImage imageNamed:NSImageNameFolder]; |
276 notification->set_image(gfx::Image([image retain])); | 247 notification->set_image(gfx::Image([image retain])); |
277 | 248 |
278 MockMessageCenter message_center; | 249 MockMessageCenter message_center; |
279 | 250 |
280 base::scoped_nsobject<MCNotificationController> controller( | 251 base::scoped_nsobject<MCNotificationController> controller( |
281 [[MCNotificationController alloc] initWithNotification:notification.get() | 252 [[MCNotificationController alloc] initWithNotification:notification.get() |
282 messageCenter:&message_center]); | 253 messageCenter:&message_center]); |
283 [controller view]; | 254 [controller view]; |
(...skipping 11 matching lines...) Expand all Loading... |
295 UTF8ToUTF16("First title"), UTF8ToUTF16("first message")); | 266 UTF8ToUTF16("First title"), UTF8ToUTF16("first message")); |
296 optional.items.push_back(item1); | 267 optional.items.push_back(item1); |
297 message_center::NotificationItem item2( | 268 message_center::NotificationItem item2( |
298 UTF8ToUTF16("Second title"), | 269 UTF8ToUTF16("Second title"), |
299 UTF8ToUTF16("second slightly longer message")); | 270 UTF8ToUTF16("second slightly longer message")); |
300 optional.items.push_back(item2); | 271 optional.items.push_back(item2); |
301 message_center::NotificationItem item3( | 272 message_center::NotificationItem item3( |
302 UTF8ToUTF16(""), // Test for empty string. | 273 UTF8ToUTF16(""), // Test for empty string. |
303 UTF8ToUTF16(" ")); // Test for string containing only spaces. | 274 UTF8ToUTF16(" ")); // Test for string containing only spaces. |
304 optional.items.push_back(item3); | 275 optional.items.push_back(item3); |
305 optional.context_message = UTF8ToUTF16("Context Message"); | 276 optional.context_message.message = UTF8ToUTF16("Context Message"); |
| 277 optional.context_message.use_origin_as_context = false; |
306 | 278 |
307 scoped_ptr<message_center::Notification> notification( | 279 scoped_ptr<message_center::Notification> notification( |
308 new message_center::Notification( | 280 new message_center::Notification( |
309 message_center::NOTIFICATION_TYPE_BASE_FORMAT, | 281 message_center::NOTIFICATION_TYPE_BASE_FORMAT, "an_id", |
310 "an_id", | |
311 UTF8ToUTF16("Notification Title"), | 282 UTF8ToUTF16("Notification Title"), |
312 UTF8ToUTF16("Notification Message - should be hidden"), | 283 UTF8ToUTF16("Notification Message - should be hidden"), gfx::Image(), |
313 gfx::Image(), | 284 base::string16(), GURL(), DummyNotifierId(), optional, NULL)); |
314 base::string16(), | |
315 DummyNotifierId(), | |
316 optional, | |
317 NULL)); | |
318 | 285 |
319 MockMessageCenter message_center; | 286 MockMessageCenter message_center; |
320 base::scoped_nsobject<MCNotificationController> controller( | 287 base::scoped_nsobject<MCNotificationController> controller( |
321 [[MCNotificationController alloc] initWithNotification:notification.get() | 288 [[MCNotificationController alloc] initWithNotification:notification.get() |
322 messageCenter:&message_center]); | 289 messageCenter:&message_center]); |
323 [controller view]; | 290 [controller view]; |
324 | 291 |
325 EXPECT_FALSE([[controller titleView] isHidden]); | 292 EXPECT_FALSE([[controller titleView] isHidden]); |
326 EXPECT_TRUE([[controller messageView] isHidden]); | 293 EXPECT_TRUE([[controller messageView] isHidden]); |
327 EXPECT_FALSE([[controller contextMessageView] isHidden]); | 294 EXPECT_FALSE([[controller contextMessageView] isHidden]); |
328 | 295 |
329 EXPECT_EQ(3u, [[[controller listView] subviews] count]); | 296 EXPECT_EQ(3u, [[[controller listView] subviews] count]); |
330 EXPECT_LT(NSMaxY([[controller listView] frame]), | 297 EXPECT_LT(NSMaxY([[controller listView] frame]), |
331 NSMinY([[controller titleView] frame])); | 298 NSMinY([[controller titleView] frame])); |
332 } | 299 } |
333 | 300 |
334 TEST_F(NotificationControllerTest, NoMessage) { | 301 TEST_F(NotificationControllerTest, NoMessage) { |
335 message_center::RichNotificationData optional; | 302 message_center::RichNotificationData optional; |
336 optional.context_message = UTF8ToUTF16("Context Message"); | 303 optional.context_message.message = UTF8ToUTF16("Context Message"); |
| 304 optional.context_message.use_origin_as_context = false; |
337 | 305 |
338 scoped_ptr<message_center::Notification> notification( | 306 scoped_ptr<message_center::Notification> notification( |
339 new message_center::Notification( | 307 new message_center::Notification( |
340 message_center::NOTIFICATION_TYPE_BASE_FORMAT, | 308 message_center::NOTIFICATION_TYPE_BASE_FORMAT, "an_id", |
341 "an_id", | 309 UTF8ToUTF16("Notification Title"), UTF8ToUTF16(""), gfx::Image(), |
342 UTF8ToUTF16("Notification Title"), | 310 base::string16(), GURL(), DummyNotifierId(), optional, NULL)); |
343 UTF8ToUTF16(""), | |
344 gfx::Image(), | |
345 base::string16(), | |
346 DummyNotifierId(), | |
347 optional, | |
348 NULL)); | |
349 | 311 |
350 MockMessageCenter message_center; | 312 MockMessageCenter message_center; |
351 base::scoped_nsobject<MCNotificationController> controller( | 313 base::scoped_nsobject<MCNotificationController> controller( |
352 [[MCNotificationController alloc] initWithNotification:notification.get() | 314 [[MCNotificationController alloc] initWithNotification:notification.get() |
353 messageCenter:&message_center]); | 315 messageCenter:&message_center]); |
354 [controller view]; | 316 [controller view]; |
355 | 317 |
356 EXPECT_FALSE([[controller titleView] isHidden]); | 318 EXPECT_FALSE([[controller titleView] isHidden]); |
357 EXPECT_TRUE([[controller messageView] isHidden]); | 319 EXPECT_TRUE([[controller messageView] isHidden]); |
358 EXPECT_FALSE([[controller contextMessageView] isHidden]); | 320 EXPECT_FALSE([[controller contextMessageView] isHidden]); |
359 } | 321 } |
360 | 322 |
361 TEST_F(NotificationControllerTest, MessageSize) { | 323 TEST_F(NotificationControllerTest, MessageSize) { |
362 message_center::RichNotificationData data; | 324 message_center::RichNotificationData data; |
363 std::string id("id"); | 325 std::string id("id"); |
364 NotifierId notifier_id(NotifierId::APPLICATION, "notifier"); | 326 NotifierId notifier_id(NotifierId::APPLICATION, "notifier"); |
365 scoped_ptr<Notification> notification(new Notification( | 327 scoped_ptr<Notification> notification(new Notification( |
366 NOTIFICATION_TYPE_BASE_FORMAT, | 328 NOTIFICATION_TYPE_BASE_FORMAT, id, base::UTF8ToUTF16(""), |
367 id, | |
368 base::UTF8ToUTF16(""), | |
369 ASCIIToUTF16("And\neven\nthe\nmessage is long.\nThis sure is wordy"), | 329 ASCIIToUTF16("And\neven\nthe\nmessage is long.\nThis sure is wordy"), |
370 gfx::Image(), | 330 gfx::Image(), base::string16() /* display_source */, GURL(), notifier_id, |
371 base::string16() /* display_source */, | 331 data, NULL /* delegate */)); |
372 notifier_id, | |
373 data, | |
374 NULL /* delegate */)); | |
375 | 332 |
376 base::scoped_nsobject<MCNotificationController> controller( | 333 base::scoped_nsobject<MCNotificationController> controller( |
377 [[MCNotificationController alloc] initWithNotification:notification.get() | 334 [[MCNotificationController alloc] initWithNotification:notification.get() |
378 messageCenter:NULL]); | 335 messageCenter:NULL]); |
379 | 336 |
380 // Set up the default layout. | 337 // Set up the default layout. |
381 [controller view]; | 338 [controller view]; |
382 | 339 |
383 auto compute_message_lines = ^{ | 340 auto compute_message_lines = ^{ |
384 NSString* string = [[[controller messageView] textStorage] string]; | 341 NSString* string = [[[controller messageView] textStorage] string]; |
(...skipping 30 matching lines...) Expand all Loading... |
415 notification->set_title(ASCIIToUTF16("one line")); | 372 notification->set_title(ASCIIToUTF16("one line")); |
416 [controller updateNotification:notification.get()]; | 373 [controller updateNotification:notification.get()]; |
417 EXPECT_EQ(2u, compute_message_lines()); | 374 EXPECT_EQ(2u, compute_message_lines()); |
418 | 375 |
419 // Message, image and two line title: 1 lines. | 376 // Message, image and two line title: 1 lines. |
420 notification->set_title(ASCIIToUTF16("two\nlines")); | 377 notification->set_title(ASCIIToUTF16("two\nlines")); |
421 [controller updateNotification:notification.get()]; | 378 [controller updateNotification:notification.get()]; |
422 EXPECT_EQ(1u, compute_message_lines()); | 379 EXPECT_EQ(1u, compute_message_lines()); |
423 | 380 |
424 // Same as above, but context message takes away from message lines. | 381 // Same as above, but context message takes away from message lines. |
425 notification->set_context_message(base::UTF8ToUTF16("foo")); | 382 notification->set_context_message(UTF8ToUTF16("foo"), false); |
426 notification->set_title(ASCIIToUTF16("")); | 383 notification->set_title(ASCIIToUTF16("")); |
427 [controller updateNotification:notification.get()]; | 384 [controller updateNotification:notification.get()]; |
428 EXPECT_EQ(1u, compute_message_lines()); | 385 EXPECT_EQ(1u, compute_message_lines()); |
429 | 386 |
430 notification->set_title(ASCIIToUTF16("one line")); | 387 notification->set_title(ASCIIToUTF16("one line")); |
431 [controller updateNotification:notification.get()]; | 388 [controller updateNotification:notification.get()]; |
432 EXPECT_EQ(1u, compute_message_lines()); | 389 EXPECT_EQ(1u, compute_message_lines()); |
433 | 390 |
434 notification->set_title(ASCIIToUTF16("two\nlines")); | 391 notification->set_title(ASCIIToUTF16("two\nlines")); |
435 [controller updateNotification:notification.get()]; | 392 [controller updateNotification:notification.get()]; |
436 EXPECT_EQ(0u, compute_message_lines()); | 393 EXPECT_EQ(0u, compute_message_lines()); |
437 } | 394 } |
438 | 395 |
439 } // namespace message_center | 396 } // namespace message_center |
OLD | NEW |