| 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 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 void TearDown() override { | 35 void TearDown() override { |
| 36 [notification_center_ removeAllDeliveredNotifications]; | 36 [notification_center_ removeAllDeliveredNotifications]; |
| 37 [alert_dispatcher_ closeAllNotifications]; | 37 [alert_dispatcher_ closeAllNotifications]; |
| 38 } | 38 } |
| 39 | 39 |
| 40 protected: | 40 protected: |
| 41 NSUserNotification* BuildNotification() { | 41 NSUserNotification* BuildNotification() { |
| 42 base::scoped_nsobject<NotificationBuilder> builder( | 42 base::scoped_nsobject<NotificationBuilder> builder( |
| 43 [[NotificationBuilder alloc] initWithCloseLabel:@"Close" | 43 [[NotificationBuilder alloc] initWithCloseLabel:@"Close" |
| 44 optionsLabel:@"Options" | 44 optionsLabel:@"More" |
| 45 settingsLabel:@"Settings"]); | 45 settingsLabel:@"Settings"]); |
| 46 [builder setTitle:@"Title"]; | 46 [builder setTitle:@"Title"]; |
| 47 [builder setSubTitle:@"https://www.miguel.com"]; | 47 [builder setSubTitle:@"https://www.miguel.com"]; |
| 48 [builder setOrigin:@"https://www.miguel.com/"]; | 48 [builder setOrigin:@"https://www.miguel.com/"]; |
| 49 [builder setContextMessage:@""]; | 49 [builder setContextMessage:@""]; |
| 50 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; | 50 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; |
| 51 [builder setTag:@"tag1"]; | 51 [builder setTag:@"tag1"]; |
| 52 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; | 52 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
| 53 [builder setNotificationId:@"notification_id"]; | 53 [builder setNotificationId:@"notification_id"]; |
| 54 [builder setProfileId:@"profile_id"]; | 54 [builder setProfileId:@"profile_id"]; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", | 228 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
| 229 "profile_id", false, *notification); | 229 "profile_id", false, *notification); |
| 230 | 230 |
| 231 NSArray* notifications = [notification_center() deliveredNotifications]; | 231 NSArray* notifications = [notification_center() deliveredNotifications]; |
| 232 EXPECT_EQ(1u, [notifications count]); | 232 EXPECT_EQ(1u, [notifications count]); |
| 233 NSUserNotification* delivered_notification = [notifications objectAtIndex:0]; | 233 NSUserNotification* delivered_notification = [notifications objectAtIndex:0]; |
| 234 EXPECT_NSEQ(@"Title", [delivered_notification title]); | 234 EXPECT_NSEQ(@"Title", [delivered_notification title]); |
| 235 EXPECT_NSEQ(@"Context", [delivered_notification informativeText]); | 235 EXPECT_NSEQ(@"Context", [delivered_notification informativeText]); |
| 236 EXPECT_NSEQ(@"https://gmail.com", [delivered_notification subtitle]); | 236 EXPECT_NSEQ(@"https://gmail.com", [delivered_notification subtitle]); |
| 237 EXPECT_NSEQ(@"Close", [delivered_notification otherButtonTitle]); | 237 EXPECT_NSEQ(@"Close", [delivered_notification otherButtonTitle]); |
| 238 EXPECT_NSEQ(@"Options", [delivered_notification actionButtonTitle]); | 238 EXPECT_NSEQ(@"More", [delivered_notification actionButtonTitle]); |
| 239 } | 239 } |
| 240 | 240 |
| 241 TEST_F(NotificationPlatformBridgeMacTest, TestCloseNotification) { | 241 TEST_F(NotificationPlatformBridgeMacTest, TestCloseNotification) { |
| 242 std::unique_ptr<Notification> notification = CreateBanner( | 242 std::unique_ptr<Notification> notification = CreateBanner( |
| 243 "Title", "Context", "https://gmail.com", "Button 1", nullptr); | 243 "Title", "Context", "https://gmail.com", "Button 1", nullptr); |
| 244 | 244 |
| 245 std::unique_ptr<NotificationPlatformBridgeMac> bridge( | 245 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
| 246 new NotificationPlatformBridgeMac(notification_center(), nil)); | 246 new NotificationPlatformBridgeMac(notification_center(), nil)); |
| 247 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); | 247 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
| 248 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", | 248 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); | 383 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); |
| 384 EXPECT_EQ(1u, [[alert_dispatcher() alerts] count]); | 384 EXPECT_EQ(1u, [[alert_dispatcher() alerts] count]); |
| 385 } | 385 } |
| 386 | 386 |
| 387 // The destructor of the bridge should close all notifications. | 387 // The destructor of the bridge should close all notifications. |
| 388 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); | 388 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
| 389 EXPECT_EQ(0u, [[alert_dispatcher() alerts] count]); | 389 EXPECT_EQ(0u, [[alert_dispatcher() alerts] count]); |
| 390 } | 390 } |
| 391 | 391 |
| 392 #endif | 392 #endif |
| OLD | NEW |