OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <AppKit/AppKit.h> | 5 #import <AppKit/AppKit.h> |
6 #import <objc/runtime.h> | 6 #import <objc/runtime.h> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 // If however the origin is not present the response should be fine. | 197 // If however the origin is not present the response should be fine. |
198 [response removeObjectForKey:notification_constants::kNotificationOrigin]; | 198 [response removeObjectForKey:notification_constants::kNotificationOrigin]; |
199 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); | 199 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
200 } | 200 } |
201 | 201 |
202 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayNoButtons) { | 202 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayNoButtons) { |
203 std::unique_ptr<Notification> notification = | 203 std::unique_ptr<Notification> notification = |
204 CreateBanner("Title", "Context", "https://gmail.com", nullptr, nullptr); | 204 CreateBanner("Title", "Context", "https://gmail.com", nullptr, nullptr); |
205 | 205 |
206 std::unique_ptr<NotificationPlatformBridgeMac> bridge( | 206 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
207 new NotificationPlatformBridgeMac(notification_center(), nil)); | 207 new NotificationPlatformBridgeMac(notification_center(), |
| 208 alert_dispatcher())); |
208 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", | 209 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
209 "profile_id", false, *notification); | 210 "profile_id", false, *notification); |
210 NSArray* notifications = [notification_center() deliveredNotifications]; | 211 NSArray* notifications = [notification_center() deliveredNotifications]; |
211 | 212 |
212 EXPECT_EQ(1u, [notifications count]); | 213 EXPECT_EQ(1u, [notifications count]); |
213 | 214 |
214 NSUserNotification* delivered_notification = [notifications objectAtIndex:0]; | 215 NSUserNotification* delivered_notification = [notifications objectAtIndex:0]; |
215 EXPECT_NSEQ(@"Title", [delivered_notification title]); | 216 EXPECT_NSEQ(@"Title", [delivered_notification title]); |
216 EXPECT_NSEQ(@"Context", [delivered_notification informativeText]); | 217 EXPECT_NSEQ(@"Context", [delivered_notification informativeText]); |
217 EXPECT_NSEQ(@"https://gmail.com", [delivered_notification subtitle]); | 218 EXPECT_NSEQ(@"https://gmail.com", [delivered_notification subtitle]); |
218 EXPECT_NSEQ(@"Close", [delivered_notification otherButtonTitle]); | 219 EXPECT_NSEQ(@"Close", [delivered_notification otherButtonTitle]); |
219 EXPECT_NSEQ(@"Settings", [delivered_notification actionButtonTitle]); | 220 EXPECT_NSEQ(@"Settings", [delivered_notification actionButtonTitle]); |
220 } | 221 } |
221 | 222 |
222 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayOneButton) { | 223 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayOneButton) { |
223 std::unique_ptr<Notification> notification = CreateBanner( | 224 std::unique_ptr<Notification> notification = CreateBanner( |
224 "Title", "Context", "https://gmail.com", "Button 1", nullptr); | 225 "Title", "Context", "https://gmail.com", "Button 1", nullptr); |
225 | 226 |
226 std::unique_ptr<NotificationPlatformBridgeMac> bridge( | 227 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
227 new NotificationPlatformBridgeMac(notification_center(), nil)); | 228 new NotificationPlatformBridgeMac(notification_center(), |
| 229 alert_dispatcher())); |
228 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", | 230 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
229 "profile_id", false, *notification); | 231 "profile_id", false, *notification); |
230 | 232 |
231 NSArray* notifications = [notification_center() deliveredNotifications]; | 233 NSArray* notifications = [notification_center() deliveredNotifications]; |
232 EXPECT_EQ(1u, [notifications count]); | 234 EXPECT_EQ(1u, [notifications count]); |
233 NSUserNotification* delivered_notification = [notifications objectAtIndex:0]; | 235 NSUserNotification* delivered_notification = [notifications objectAtIndex:0]; |
234 EXPECT_NSEQ(@"Title", [delivered_notification title]); | 236 EXPECT_NSEQ(@"Title", [delivered_notification title]); |
235 EXPECT_NSEQ(@"Context", [delivered_notification informativeText]); | 237 EXPECT_NSEQ(@"Context", [delivered_notification informativeText]); |
236 EXPECT_NSEQ(@"https://gmail.com", [delivered_notification subtitle]); | 238 EXPECT_NSEQ(@"https://gmail.com", [delivered_notification subtitle]); |
237 EXPECT_NSEQ(@"Close", [delivered_notification otherButtonTitle]); | 239 EXPECT_NSEQ(@"Close", [delivered_notification otherButtonTitle]); |
238 EXPECT_NSEQ(@"More", [delivered_notification actionButtonTitle]); | 240 EXPECT_NSEQ(@"More", [delivered_notification actionButtonTitle]); |
239 } | 241 } |
240 | 242 |
241 TEST_F(NotificationPlatformBridgeMacTest, TestCloseNotification) { | 243 TEST_F(NotificationPlatformBridgeMacTest, TestCloseNotification) { |
242 std::unique_ptr<Notification> notification = CreateBanner( | 244 std::unique_ptr<Notification> notification = CreateBanner( |
243 "Title", "Context", "https://gmail.com", "Button 1", nullptr); | 245 "Title", "Context", "https://gmail.com", "Button 1", nullptr); |
244 | 246 |
245 std::unique_ptr<NotificationPlatformBridgeMac> bridge( | 247 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
246 new NotificationPlatformBridgeMac(notification_center(), nil)); | 248 new NotificationPlatformBridgeMac(notification_center(), |
| 249 alert_dispatcher())); |
247 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); | 250 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
248 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", | 251 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
249 "profile_id", false, *notification); | 252 "profile_id", false, *notification); |
250 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); | 253 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); |
251 | 254 |
252 bridge->Close("profile_id", "notification_id"); | 255 bridge->Close("profile_id", "notification_id"); |
253 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); | 256 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
254 } | 257 } |
255 | 258 |
256 TEST_F(NotificationPlatformBridgeMacTest, TestCloseNonExistingNotification) { | 259 TEST_F(NotificationPlatformBridgeMacTest, TestCloseNonExistingNotification) { |
257 std::unique_ptr<Notification> notification = CreateBanner( | 260 std::unique_ptr<Notification> notification = CreateBanner( |
258 "Title", "Context", "https://gmail.com", "Button 1", nullptr); | 261 "Title", "Context", "https://gmail.com", "Button 1", nullptr); |
259 | 262 |
260 std::unique_ptr<NotificationPlatformBridgeMac> bridge( | 263 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
261 new NotificationPlatformBridgeMac(notification_center(), nil)); | 264 new NotificationPlatformBridgeMac(notification_center(), |
| 265 alert_dispatcher())); |
262 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); | 266 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
263 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", | 267 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
264 "profile_id", false, *notification); | 268 "profile_id", false, *notification); |
265 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); | 269 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); |
266 | 270 |
267 bridge->Close("profile_id_does_not_exist", "notification_id"); | 271 bridge->Close("profile_id_does_not_exist", "notification_id"); |
268 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); | 272 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); |
269 } | 273 } |
270 | 274 |
271 TEST_F(NotificationPlatformBridgeMacTest, TestGetDisplayed) { | 275 TEST_F(NotificationPlatformBridgeMacTest, TestGetDisplayed) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 base::Bind(&StoreNotificationCount, ¬ification_count)); | 307 base::Bind(&StoreNotificationCount, ¬ification_count)); |
304 base::RunLoop().RunUntilIdle(); | 308 base::RunLoop().RunUntilIdle(); |
305 EXPECT_EQ(0, notification_count); | 309 EXPECT_EQ(0, notification_count); |
306 } | 310 } |
307 | 311 |
308 TEST_F(NotificationPlatformBridgeMacTest, TestQuitRemovesNotifications) { | 312 TEST_F(NotificationPlatformBridgeMacTest, TestQuitRemovesNotifications) { |
309 std::unique_ptr<Notification> notification = CreateBanner( | 313 std::unique_ptr<Notification> notification = CreateBanner( |
310 "Title", "Context", "https://gmail.com", "Button 1", nullptr); | 314 "Title", "Context", "https://gmail.com", "Button 1", nullptr); |
311 { | 315 { |
312 std::unique_ptr<NotificationPlatformBridgeMac> bridge( | 316 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
313 new NotificationPlatformBridgeMac(notification_center(), nil)); | 317 new NotificationPlatformBridgeMac(notification_center(), |
| 318 alert_dispatcher())); |
314 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); | 319 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
315 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", | 320 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
316 "profile_id", false, *notification); | 321 "profile_id", false, *notification); |
317 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); | 322 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); |
318 } | 323 } |
319 | 324 |
320 // The destructor of the bridge should close all notifications. | 325 // The destructor of the bridge should close all notifications. |
321 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); | 326 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
322 } | 327 } |
323 | 328 |
324 // TODO(miguelg) There is some duplication between these tests and the ones | |
325 // Above. Once the flag is removed most tests can be merged. | |
326 #if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS) | |
327 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayAlert) { | 329 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayAlert) { |
328 std::unique_ptr<Notification> alert = | 330 std::unique_ptr<Notification> alert = |
329 CreateAlert("Title", "Context", "https://gmail.com", "Button 1", nullptr); | 331 CreateAlert("Title", "Context", "https://gmail.com", "Button 1", nullptr); |
330 std::unique_ptr<NotificationPlatformBridgeMac> bridge( | 332 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
331 new NotificationPlatformBridgeMac(notification_center(), | 333 new NotificationPlatformBridgeMac(notification_center(), |
332 alert_dispatcher())); | 334 alert_dispatcher())); |
333 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", | 335 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
334 "profile_id", false, *alert); | 336 "profile_id", false, *alert); |
335 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); | 337 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
336 EXPECT_EQ(1u, [[alert_dispatcher() alerts] count]); | 338 EXPECT_EQ(1u, [[alert_dispatcher() alerts] count]); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 bridge->Display(NotificationCommon::PERSISTENT, "notification_id2", | 385 bridge->Display(NotificationCommon::PERSISTENT, "notification_id2", |
384 "profile_id", false, *alert); | 386 "profile_id", false, *alert); |
385 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); | 387 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); |
386 EXPECT_EQ(1u, [[alert_dispatcher() alerts] count]); | 388 EXPECT_EQ(1u, [[alert_dispatcher() alerts] count]); |
387 } | 389 } |
388 | 390 |
389 // The destructor of the bridge should close all notifications. | 391 // The destructor of the bridge should close all notifications. |
390 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); | 392 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
391 EXPECT_EQ(0u, [[alert_dispatcher() alerts] count]); | 393 EXPECT_EQ(0u, [[alert_dispatcher() alerts] count]); |
392 } | 394 } |
393 | |
394 #endif | |
OLD | NEW |