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/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
9 #import "base/mac/scoped_objc_class_swizzler.h" | |
10 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/notifications/notification.h" | 10 #include "chrome/browser/notifications/notification.h" |
12 #include "chrome/browser/notifications/notification_platform_bridge_mac.h" | 11 #include "chrome/browser/notifications/notification_platform_bridge_mac.h" |
13 #include "chrome/browser/notifications/notification_test_util.h" | 12 #include "chrome/browser/notifications/notification_test_util.h" |
| 13 #include "chrome/browser/notifications/stub_alert_dispatcher_mac.h" |
14 #include "chrome/browser/notifications/stub_notification_center_mac.h" | 14 #include "chrome/browser/notifications/stub_notification_center_mac.h" |
15 #include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" | 15 #include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" |
16 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" | 16 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" |
17 #include "chrome/browser/ui/cocoa/notifications/notification_response_builder_ma
c.h" | 17 #include "chrome/browser/ui/cocoa/notifications/notification_response_builder_ma
c.h" |
| 18 #include "chrome/common/features.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "testing/gtest_mac.h" | 20 #include "testing/gtest_mac.h" |
20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
21 | 22 |
22 class NotificationPlatformBridgeMacTest : public testing::Test { | 23 class NotificationPlatformBridgeMacTest : public testing::Test { |
23 public: | 24 public: |
24 void SetUp() override { | 25 void SetUp() override { |
25 notification_center_.reset([[StubNotificationCenter alloc] init]); | 26 notification_center_.reset([[StubNotificationCenter alloc] init]); |
| 27 alert_dispatcher_.reset([[StubAlertDispatcher alloc] init]); |
26 } | 28 } |
27 | 29 |
28 void TearDown() override { | 30 void TearDown() override { |
29 [notification_center_ removeAllDeliveredNotifications]; | 31 [notification_center_ removeAllDeliveredNotifications]; |
| 32 [alert_dispatcher_ closeAllNotifications]; |
30 } | 33 } |
31 | 34 |
32 protected: | 35 protected: |
33 NSUserNotification* BuildNotification() { | 36 NSUserNotification* BuildNotification() { |
34 base::scoped_nsobject<NotificationBuilder> builder( | 37 base::scoped_nsobject<NotificationBuilder> builder( |
35 [[NotificationBuilder alloc] initWithCloseLabel:@"Close" | 38 [[NotificationBuilder alloc] initWithCloseLabel:@"Close" |
36 optionsLabel:@"Options" | 39 optionsLabel:@"Options" |
37 settingsLabel:@"Settings"]); | 40 settingsLabel:@"Settings"]); |
38 [builder setTitle:@"Title"]; | 41 [builder setTitle:@"Title"]; |
39 [builder setSubTitle:@"https://www.miguel.com"]; | 42 [builder setSubTitle:@"https://www.miguel.com"]; |
40 [builder setOrigin:@"https://www.miguel.com/"]; | 43 [builder setOrigin:@"https://www.miguel.com/"]; |
41 [builder setContextMessage:@""]; | 44 [builder setContextMessage:@""]; |
42 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; | 45 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; |
43 [builder setTag:@"tag1"]; | 46 [builder setTag:@"tag1"]; |
44 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; | 47 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
45 [builder setNotificationId:@"notification_id"]; | 48 [builder setNotificationId:@"notification_id"]; |
46 [builder setProfileId:@"profile_id"]; | 49 [builder setProfileId:@"profile_id"]; |
47 [builder setIncognito:false]; | 50 [builder setIncognito:false]; |
48 [builder setNotificationType:@(NotificationCommon::PERSISTENT)]; | 51 [builder setNotificationType:@(NotificationCommon::PERSISTENT)]; |
49 | 52 |
50 return [builder buildUserNotification]; | 53 return [builder buildUserNotification]; |
51 } | 54 } |
52 | 55 |
| 56 std::unique_ptr<Notification> CreateBanner(const char* title, |
| 57 const char* subtitle, |
| 58 const char* origin, |
| 59 const char* button1, |
| 60 const char* button2) { |
| 61 return CreateNotification(title, subtitle, origin, button1, button2, |
| 62 false /* require_interaction */); |
| 63 } |
| 64 |
| 65 std::unique_ptr<Notification> CreateAlert(const char* title, |
| 66 const char* subtitle, |
| 67 const char* origin, |
| 68 const char* button1, |
| 69 const char* button2) { |
| 70 return CreateNotification(title, subtitle, origin, button1, button2, |
| 71 true /* require_interaction */); |
| 72 } |
| 73 |
53 std::unique_ptr<Notification> CreateNotification(const char* title, | 74 std::unique_ptr<Notification> CreateNotification(const char* title, |
54 const char* subtitle, | 75 const char* subtitle, |
55 const char* origin, | 76 const char* origin, |
56 const char* button1, | 77 const char* button1, |
57 const char* button2) { | 78 const char* button2, |
| 79 bool require_interaction) { |
58 message_center::RichNotificationData optional_fields; | 80 message_center::RichNotificationData optional_fields; |
59 optional_fields.context_message = base::UTF8ToUTF16(origin); | 81 optional_fields.context_message = base::UTF8ToUTF16(origin); |
60 if (button1) { | 82 if (button1) { |
61 optional_fields.buttons.push_back( | 83 optional_fields.buttons.push_back( |
62 message_center::ButtonInfo(base::UTF8ToUTF16(button1))); | 84 message_center::ButtonInfo(base::UTF8ToUTF16(button1))); |
63 if (button2) { | 85 if (button2) { |
64 optional_fields.buttons.push_back( | 86 optional_fields.buttons.push_back( |
65 message_center::ButtonInfo(base::UTF8ToUTF16(button2))); | 87 message_center::ButtonInfo(base::UTF8ToUTF16(button2))); |
66 } | 88 } |
67 } | 89 } |
68 | 90 |
69 GURL url = GURL(origin); | 91 GURL url = GURL(origin); |
70 | 92 |
71 std::unique_ptr<Notification> notification(new Notification( | 93 std::unique_ptr<Notification> notification(new Notification( |
72 message_center::NOTIFICATION_TYPE_SIMPLE, base::UTF8ToUTF16(title), | 94 message_center::NOTIFICATION_TYPE_SIMPLE, base::UTF8ToUTF16(title), |
73 base::UTF8ToUTF16(subtitle), gfx::Image(), | 95 base::UTF8ToUTF16(subtitle), gfx::Image(), |
74 message_center::NotifierId(url), base::UTF8ToUTF16("Notifier's Name"), | 96 message_center::NotifierId(url), base::UTF8ToUTF16("Notifier's Name"), |
75 url, "id1", optional_fields, new MockNotificationDelegate("id1"))); | 97 url, "id1", optional_fields, new MockNotificationDelegate("id1"))); |
| 98 if (require_interaction) |
| 99 notification->set_never_timeout(true); |
76 | 100 |
77 return notification; | 101 return notification; |
78 } | 102 } |
79 | 103 |
80 NSMutableDictionary* BuildDefaultNotificationResponse() { | 104 NSMutableDictionary* BuildDefaultNotificationResponse() { |
81 return [NSMutableDictionary | 105 return [NSMutableDictionary |
82 dictionaryWithDictionary:[NotificationResponseBuilder | 106 dictionaryWithDictionary:[NotificationResponseBuilder |
83 buildDictionary:BuildNotification()]]; | 107 buildDictionary:BuildNotification()]]; |
84 } | 108 } |
85 | 109 |
86 NSUserNotificationCenter* notification_center() { | 110 NSUserNotificationCenter* notification_center() { |
87 return notification_center_.get(); | 111 return notification_center_.get(); |
88 } | 112 } |
89 | 113 |
| 114 StubAlertDispatcher* alert_dispatcher() { return alert_dispatcher_.get(); } |
| 115 |
90 private: | 116 private: |
91 base::scoped_nsobject<StubNotificationCenter> notification_center_; | 117 base::scoped_nsobject<StubNotificationCenter> notification_center_; |
| 118 base::scoped_nsobject<StubAlertDispatcher> alert_dispatcher_; |
92 }; | 119 }; |
93 | 120 |
94 TEST_F(NotificationPlatformBridgeMacTest, TestNotificationVerifyValidResponse) { | 121 TEST_F(NotificationPlatformBridgeMacTest, TestNotificationVerifyValidResponse) { |
95 NSDictionary* response = BuildDefaultNotificationResponse(); | 122 NSDictionary* response = BuildDefaultNotificationResponse(); |
96 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); | 123 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
97 } | 124 } |
98 | 125 |
99 TEST_F(NotificationPlatformBridgeMacTest, TestNotificationUnknownType) { | 126 TEST_F(NotificationPlatformBridgeMacTest, TestNotificationUnknownType) { |
100 NSMutableDictionary* response = BuildDefaultNotificationResponse(); | 127 NSMutableDictionary* response = BuildDefaultNotificationResponse(); |
101 [response setValue:[NSNumber numberWithInt:210581] | 128 [response setValue:[NSNumber numberWithInt:210581] |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 [response setValue:@"invalidorigin" | 178 [response setValue:@"invalidorigin" |
152 forKey:notification_constants::kNotificationOrigin]; | 179 forKey:notification_constants::kNotificationOrigin]; |
153 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); | 180 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
154 | 181 |
155 // If however the origin is not present the response should be fine. | 182 // If however the origin is not present the response should be fine. |
156 [response removeObjectForKey:notification_constants::kNotificationOrigin]; | 183 [response removeObjectForKey:notification_constants::kNotificationOrigin]; |
157 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); | 184 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
158 } | 185 } |
159 | 186 |
160 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayNoButtons) { | 187 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayNoButtons) { |
161 std::unique_ptr<Notification> notification = CreateNotification( | 188 std::unique_ptr<Notification> notification = |
162 "Title", "Context", "https://gmail.com", nullptr, nullptr); | 189 CreateBanner("Title", "Context", "https://gmail.com", nullptr, nullptr); |
163 | 190 |
164 std::unique_ptr<NotificationPlatformBridgeMac> bridge( | 191 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
165 new NotificationPlatformBridgeMac(notification_center())); | 192 new NotificationPlatformBridgeMac(notification_center(), nil)); |
166 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", | 193 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
167 "profile_id", false, *notification); | 194 "profile_id", false, *notification); |
168 NSArray* notifications = [notification_center() deliveredNotifications]; | 195 NSArray* notifications = [notification_center() deliveredNotifications]; |
169 | 196 |
170 EXPECT_EQ(1u, [notifications count]); | 197 EXPECT_EQ(1u, [notifications count]); |
171 | 198 |
172 NSUserNotification* delivered_notification = [notifications objectAtIndex:0]; | 199 NSUserNotification* delivered_notification = [notifications objectAtIndex:0]; |
173 EXPECT_NSEQ(@"Title", [delivered_notification title]); | 200 EXPECT_NSEQ(@"Title", [delivered_notification title]); |
174 EXPECT_NSEQ(@"Context", [delivered_notification informativeText]); | 201 EXPECT_NSEQ(@"Context", [delivered_notification informativeText]); |
175 EXPECT_NSEQ(@"https://gmail.com", [delivered_notification subtitle]); | 202 EXPECT_NSEQ(@"https://gmail.com", [delivered_notification subtitle]); |
176 EXPECT_NSEQ(@"Close", [delivered_notification otherButtonTitle]); | 203 EXPECT_NSEQ(@"Close", [delivered_notification otherButtonTitle]); |
177 EXPECT_NSEQ(@"Settings", [delivered_notification actionButtonTitle]); | 204 EXPECT_NSEQ(@"Settings", [delivered_notification actionButtonTitle]); |
178 } | 205 } |
179 | 206 |
180 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayOneButton) { | 207 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayOneButton) { |
181 std::unique_ptr<Notification> notification = CreateNotification( | 208 std::unique_ptr<Notification> notification = CreateBanner( |
182 "Title", "Context", "https://gmail.com", "Button 1", nullptr); | 209 "Title", "Context", "https://gmail.com", "Button 1", nullptr); |
183 | 210 |
184 std::unique_ptr<NotificationPlatformBridgeMac> bridge( | 211 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
185 new NotificationPlatformBridgeMac(notification_center())); | 212 new NotificationPlatformBridgeMac(notification_center(), nil)); |
186 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", | 213 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
187 "profile_id", false, *notification); | 214 "profile_id", false, *notification); |
188 | 215 |
189 NSArray* notifications = [notification_center() deliveredNotifications]; | 216 NSArray* notifications = [notification_center() deliveredNotifications]; |
190 EXPECT_EQ(1u, [notifications count]); | 217 EXPECT_EQ(1u, [notifications count]); |
191 NSUserNotification* delivered_notification = [notifications objectAtIndex:0]; | 218 NSUserNotification* delivered_notification = [notifications objectAtIndex:0]; |
192 EXPECT_NSEQ(@"Title", [delivered_notification title]); | 219 EXPECT_NSEQ(@"Title", [delivered_notification title]); |
193 EXPECT_NSEQ(@"Context", [delivered_notification informativeText]); | 220 EXPECT_NSEQ(@"Context", [delivered_notification informativeText]); |
194 EXPECT_NSEQ(@"https://gmail.com", [delivered_notification subtitle]); | 221 EXPECT_NSEQ(@"https://gmail.com", [delivered_notification subtitle]); |
195 EXPECT_NSEQ(@"Close", [delivered_notification otherButtonTitle]); | 222 EXPECT_NSEQ(@"Close", [delivered_notification otherButtonTitle]); |
196 EXPECT_NSEQ(@"Options", [delivered_notification actionButtonTitle]); | 223 EXPECT_NSEQ(@"Options", [delivered_notification actionButtonTitle]); |
197 } | 224 } |
198 | 225 |
199 TEST_F(NotificationPlatformBridgeMacTest, TestCloseNotification) { | 226 TEST_F(NotificationPlatformBridgeMacTest, TestCloseNotification) { |
200 std::unique_ptr<Notification> notification = CreateNotification( | 227 std::unique_ptr<Notification> notification = CreateBanner( |
201 "Title", "Context", "https://gmail.com", "Button 1", nullptr); | 228 "Title", "Context", "https://gmail.com", "Button 1", nullptr); |
202 | 229 |
203 std::unique_ptr<NotificationPlatformBridgeMac> bridge( | 230 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
204 new NotificationPlatformBridgeMac(notification_center())); | 231 new NotificationPlatformBridgeMac(notification_center(), nil)); |
205 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); | 232 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
206 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", | 233 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
207 "profile_id", false, *notification); | 234 "profile_id", false, *notification); |
208 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); | 235 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); |
209 | 236 |
210 bridge->Close("profile_id", "notification_id"); | 237 bridge->Close("profile_id", "notification_id"); |
211 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); | 238 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
212 } | 239 } |
213 | 240 |
214 TEST_F(NotificationPlatformBridgeMacTest, TestCloseNonExistingNotification) { | 241 TEST_F(NotificationPlatformBridgeMacTest, TestCloseNonExistingNotification) { |
215 std::unique_ptr<Notification> notification = CreateNotification( | 242 std::unique_ptr<Notification> notification = CreateBanner( |
216 "Title", "Context", "https://gmail.com", "Button 1", nullptr); | 243 "Title", "Context", "https://gmail.com", "Button 1", nullptr); |
217 | 244 |
218 std::unique_ptr<NotificationPlatformBridgeMac> bridge( | 245 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
219 new NotificationPlatformBridgeMac(notification_center())); | 246 new NotificationPlatformBridgeMac(notification_center(), nil)); |
220 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); | 247 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
221 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", | 248 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
222 "profile_id", false, *notification); | 249 "profile_id", false, *notification); |
223 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); | 250 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); |
224 | 251 |
225 bridge->Close("profile_id_does_not_exist", "notification_id"); | 252 bridge->Close("profile_id_does_not_exist", "notification_id"); |
226 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); | 253 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); |
227 } | 254 } |
228 | 255 |
229 TEST_F(NotificationPlatformBridgeMacTest, TestGetDisplayed) { | 256 TEST_F(NotificationPlatformBridgeMacTest, TestGetDisplayed) { |
230 std::unique_ptr<Notification> notification = CreateNotification( | 257 std::unique_ptr<Notification> notification = CreateBanner( |
231 "Title", "Context", "https://gmail.com", "Button 1", nullptr); | 258 "Title", "Context", "https://gmail.com", "Button 1", nullptr); |
232 std::unique_ptr<NotificationPlatformBridgeMac> bridge( | 259 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
233 new NotificationPlatformBridgeMac(notification_center())); | 260 new NotificationPlatformBridgeMac(notification_center(), nil)); |
234 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); | 261 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
235 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", | 262 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
236 "profile_id", false, *notification); | 263 "profile_id", false, *notification); |
237 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); | 264 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); |
238 | 265 |
239 std::set<std::string> notifications; | 266 std::set<std::string> notifications; |
240 EXPECT_TRUE(bridge->GetDisplayed("profile_id", false, ¬ifications)); | 267 EXPECT_TRUE(bridge->GetDisplayed("profile_id", false, ¬ifications)); |
241 EXPECT_EQ(1u, notifications.size()); | 268 EXPECT_EQ(1u, notifications.size()); |
242 } | 269 } |
243 | 270 |
244 TEST_F(NotificationPlatformBridgeMacTest, TestGetDisplayedUnknownProfile) { | 271 TEST_F(NotificationPlatformBridgeMacTest, TestGetDisplayedUnknownProfile) { |
245 std::unique_ptr<Notification> notification = CreateNotification( | 272 std::unique_ptr<Notification> notification = CreateBanner( |
246 "Title", "Context", "https://gmail.com", "Button 1", nullptr); | 273 "Title", "Context", "https://gmail.com", "Button 1", nullptr); |
247 std::unique_ptr<NotificationPlatformBridgeMac> bridge( | 274 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
248 new NotificationPlatformBridgeMac(notification_center())); | 275 new NotificationPlatformBridgeMac(notification_center(), nil)); |
249 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); | 276 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
250 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", | 277 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
251 "profile_id", false, *notification); | 278 "profile_id", false, *notification); |
252 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); | 279 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); |
253 | 280 |
254 std::set<std::string> notifications; | 281 std::set<std::string> notifications; |
255 EXPECT_TRUE( | 282 EXPECT_TRUE( |
256 bridge->GetDisplayed("unknown_profile_id", false, ¬ifications)); | 283 bridge->GetDisplayed("unknown_profile_id", false, ¬ifications)); |
257 EXPECT_EQ(0u, notifications.size()); | 284 EXPECT_EQ(0u, notifications.size()); |
258 } | 285 } |
259 | 286 |
260 TEST_F(NotificationPlatformBridgeMacTest, TestQuitRemovesNotifications) { | 287 TEST_F(NotificationPlatformBridgeMacTest, TestQuitRemovesNotifications) { |
261 std::unique_ptr<Notification> notification = CreateNotification( | 288 std::unique_ptr<Notification> notification = CreateBanner( |
262 "Title", "Context", "https://gmail.com", "Button 1", nullptr); | 289 "Title", "Context", "https://gmail.com", "Button 1", nullptr); |
263 { | 290 { |
264 std::unique_ptr<NotificationPlatformBridgeMac> bridge( | 291 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
265 new NotificationPlatformBridgeMac(notification_center())); | 292 new NotificationPlatformBridgeMac(notification_center(), nil)); |
266 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); | 293 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
267 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", | 294 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
268 "profile_id", false, *notification); | 295 "profile_id", false, *notification); |
269 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); | 296 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); |
270 } | 297 } |
271 | 298 |
272 // The destructor of the bridge should close all notifications. | 299 // The destructor of the bridge should close all notifications. |
273 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); | 300 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
274 } | 301 } |
| 302 |
| 303 // TODO(miguelg) There is some duplication between these tests and the ones |
| 304 // Above. Once the flag is removed most tests can be merged. |
| 305 #if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS) |
| 306 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayAlert) { |
| 307 std::unique_ptr<Notification> alert = |
| 308 CreateAlert("Title", "Context", "https://gmail.com", "Button 1", nullptr); |
| 309 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
| 310 new NotificationPlatformBridgeMac(notification_center(), |
| 311 alert_dispatcher())); |
| 312 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
| 313 "profile_id", false, *alert); |
| 314 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
| 315 EXPECT_EQ(1u, [[alert_dispatcher() alerts] count]); |
| 316 } |
| 317 |
| 318 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayBannerAndAlert) { |
| 319 std::unique_ptr<Notification> alert = |
| 320 CreateAlert("Title", "Context", "https://gmail.com", "Button 1", nullptr); |
| 321 std::unique_ptr<Notification> banner = CreateBanner( |
| 322 "Title", "Context", "https://gmail.com", "Button 1", nullptr); |
| 323 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
| 324 new NotificationPlatformBridgeMac(notification_center(), |
| 325 alert_dispatcher())); |
| 326 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
| 327 "profile_id", false, *banner); |
| 328 bridge->Display(NotificationCommon::PERSISTENT, "notification_id2", |
| 329 "profile_id", false, *alert); |
| 330 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); |
| 331 EXPECT_EQ(1u, [[alert_dispatcher() alerts] count]); |
| 332 } |
| 333 |
| 334 TEST_F(NotificationPlatformBridgeMacTest, TestCloseAlert) { |
| 335 std::unique_ptr<Notification> alert = |
| 336 CreateAlert("Title", "Context", "https://gmail.com", "Button 1", nullptr); |
| 337 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
| 338 new NotificationPlatformBridgeMac(notification_center(), |
| 339 alert_dispatcher())); |
| 340 EXPECT_EQ(0u, [[alert_dispatcher() alerts] count]); |
| 341 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
| 342 "profile_id", false, *alert); |
| 343 EXPECT_EQ(1u, [[alert_dispatcher() alerts] count]); |
| 344 |
| 345 bridge->Close("profile_id", "notification_id"); |
| 346 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
| 347 } |
| 348 |
| 349 TEST_F(NotificationPlatformBridgeMacTest, TestQuitRemovesBannersAndAlerts) { |
| 350 std::unique_ptr<Notification> notification = CreateBanner( |
| 351 "Title", "Context", "https://gmail.com", "Button 1", nullptr); |
| 352 std::unique_ptr<Notification> alert = |
| 353 CreateAlert("Title", "Context", "https://gmail.com", "Button 1", nullptr); |
| 354 { |
| 355 std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
| 356 new NotificationPlatformBridgeMac(notification_center(), |
| 357 alert_dispatcher())); |
| 358 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
| 359 EXPECT_EQ(0u, [[alert_dispatcher() alerts] count]); |
| 360 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
| 361 "profile_id", false, *notification); |
| 362 bridge->Display(NotificationCommon::PERSISTENT, "notification_id2", |
| 363 "profile_id", false, *alert); |
| 364 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); |
| 365 EXPECT_EQ(1u, [[alert_dispatcher() alerts] count]); |
| 366 } |
| 367 |
| 368 // The destructor of the bridge should close all notifications. |
| 369 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
| 370 EXPECT_EQ(0u, [[alert_dispatcher() alerts] count]); |
| 371 } |
| 372 |
| 373 #endif |
OLD | NEW |