Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1407)

Side by Side Diff: chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm

Issue 2827543003: Display ETLD+1 instead of the full domain in MacOSX native notifications (Closed)
Patch Set: format Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/notifications/notification_platform_bridge_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/i18n/number_formatting.h" 9 #include "base/i18n/number_formatting.h"
10 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
(...skipping 28 matching lines...) Expand all
39 [alert_dispatcher_ closeAllNotifications]; 39 [alert_dispatcher_ closeAllNotifications];
40 } 40 }
41 41
42 protected: 42 protected:
43 NSUserNotification* BuildNotification() { 43 NSUserNotification* BuildNotification() {
44 base::scoped_nsobject<NotificationBuilder> builder( 44 base::scoped_nsobject<NotificationBuilder> builder(
45 [[NotificationBuilder alloc] initWithCloseLabel:@"Close" 45 [[NotificationBuilder alloc] initWithCloseLabel:@"Close"
46 optionsLabel:@"More" 46 optionsLabel:@"More"
47 settingsLabel:@"Settings"]); 47 settingsLabel:@"Settings"]);
48 [builder setTitle:@"Title"]; 48 [builder setTitle:@"Title"];
49 [builder setSubTitle:@"https://www.miguel.com"];
50 [builder setOrigin:@"https://www.miguel.com/"]; 49 [builder setOrigin:@"https://www.miguel.com/"];
51 [builder setContextMessage:@""]; 50 [builder setContextMessage:@""];
52 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; 51 [builder setButtons:@"Button1" secondaryButton:@"Button2"];
53 [builder setTag:@"tag1"]; 52 [builder setTag:@"tag1"];
54 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; 53 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]];
55 [builder setNotificationId:@"notification_id"]; 54 [builder setNotificationId:@"notification_id"];
56 [builder setProfileId:@"profile_id"]; 55 [builder setProfileId:@"profile_id"];
57 [builder setIncognito:false]; 56 [builder setIncognito:false];
58 [builder setNotificationType:@(NotificationCommon::PERSISTENT)]; 57 [builder setNotificationType:@(NotificationCommon::PERSISTENT)];
59 [builder setShowSettingsButton:true]; 58 [builder setShowSettingsButton:true];
(...skipping 28 matching lines...) Expand all
88 true /* require_interaction */); 87 true /* require_interaction */);
89 } 88 }
90 89
91 std::unique_ptr<Notification> CreateNotification(const char* title, 90 std::unique_ptr<Notification> CreateNotification(const char* title,
92 const char* subtitle, 91 const char* subtitle,
93 const char* origin, 92 const char* origin,
94 const char* button1, 93 const char* button1,
95 const char* button2, 94 const char* button2,
96 bool require_interaction) { 95 bool require_interaction) {
97 message_center::RichNotificationData optional_fields; 96 message_center::RichNotificationData optional_fields;
98 optional_fields.context_message = base::UTF8ToUTF16(origin);
99 if (button1) { 97 if (button1) {
100 optional_fields.buttons.push_back( 98 optional_fields.buttons.push_back(
101 message_center::ButtonInfo(base::UTF8ToUTF16(button1))); 99 message_center::ButtonInfo(base::UTF8ToUTF16(button1)));
102 if (button2) { 100 if (button2) {
103 optional_fields.buttons.push_back( 101 optional_fields.buttons.push_back(
104 message_center::ButtonInfo(base::UTF8ToUTF16(button2))); 102 message_center::ButtonInfo(base::UTF8ToUTF16(button2)));
105 } 103 }
106 } 104 }
107 105
108 GURL url = GURL(origin); 106 GURL url = GURL(origin);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 alert_dispatcher())); 209 alert_dispatcher()));
212 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", 210 bridge->Display(NotificationCommon::PERSISTENT, "notification_id",
213 "profile_id", false, *notification); 211 "profile_id", false, *notification);
214 NSArray* notifications = [notification_center() deliveredNotifications]; 212 NSArray* notifications = [notification_center() deliveredNotifications];
215 213
216 EXPECT_EQ(1u, [notifications count]); 214 EXPECT_EQ(1u, [notifications count]);
217 215
218 NSUserNotification* delivered_notification = [notifications objectAtIndex:0]; 216 NSUserNotification* delivered_notification = [notifications objectAtIndex:0];
219 EXPECT_NSEQ(@"Title", [delivered_notification title]); 217 EXPECT_NSEQ(@"Title", [delivered_notification title]);
220 EXPECT_NSEQ(@"Context", [delivered_notification informativeText]); 218 EXPECT_NSEQ(@"Context", [delivered_notification informativeText]);
221 EXPECT_NSEQ(@"https://gmail.com", [delivered_notification subtitle]); 219 EXPECT_NSEQ(@"gmail.com", [delivered_notification subtitle]);
222 EXPECT_NSEQ(@"Close", [delivered_notification otherButtonTitle]); 220 EXPECT_NSEQ(@"Close", [delivered_notification otherButtonTitle]);
223 EXPECT_NSEQ(@"Settings", [delivered_notification actionButtonTitle]); 221 EXPECT_NSEQ(@"Settings", [delivered_notification actionButtonTitle]);
224 } 222 }
225 223
226 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayOneButton) { 224 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayOneButton) {
227 std::unique_ptr<Notification> notification = CreateBanner( 225 std::unique_ptr<Notification> notification = CreateBanner(
228 "Title", "Context", "https://gmail.com", "Button 1", nullptr); 226 "Title", "Context", "https://gmail.com", "Button 1", nullptr);
229 227
230 std::unique_ptr<NotificationPlatformBridgeMac> bridge( 228 std::unique_ptr<NotificationPlatformBridgeMac> bridge(
231 new NotificationPlatformBridgeMac(notification_center(), 229 new NotificationPlatformBridgeMac(notification_center(),
232 alert_dispatcher())); 230 alert_dispatcher()));
233 bridge->Display(NotificationCommon::PERSISTENT, "notification_id", 231 bridge->Display(NotificationCommon::PERSISTENT, "notification_id",
234 "profile_id", false, *notification); 232 "profile_id", false, *notification);
235 233
236 NSArray* notifications = [notification_center() deliveredNotifications]; 234 NSArray* notifications = [notification_center() deliveredNotifications];
237 EXPECT_EQ(1u, [notifications count]); 235 EXPECT_EQ(1u, [notifications count]);
238 NSUserNotification* delivered_notification = [notifications objectAtIndex:0]; 236 NSUserNotification* delivered_notification = [notifications objectAtIndex:0];
239 EXPECT_NSEQ(@"Title", [delivered_notification title]); 237 EXPECT_NSEQ(@"Title", [delivered_notification title]);
240 EXPECT_NSEQ(@"Context", [delivered_notification informativeText]); 238 EXPECT_NSEQ(@"Context", [delivered_notification informativeText]);
241 EXPECT_NSEQ(@"https://gmail.com", [delivered_notification subtitle]); 239 EXPECT_NSEQ(@"gmail.com", [delivered_notification subtitle]);
242 EXPECT_NSEQ(@"Close", [delivered_notification otherButtonTitle]); 240 EXPECT_NSEQ(@"Close", [delivered_notification otherButtonTitle]);
243 EXPECT_NSEQ(@"More", [delivered_notification actionButtonTitle]); 241 EXPECT_NSEQ(@"More", [delivered_notification actionButtonTitle]);
244 } 242 }
245 243
246 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayProgress) { 244 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayProgress) {
247 std::unique_ptr<Notification> notification = 245 std::unique_ptr<Notification> notification =
248 CreateBanner("Title", "Context", "https://gmail.com", nullptr, nullptr); 246 CreateBanner("Title", "Context", "https://gmail.com", nullptr, nullptr);
249 const int kSamplePercent = 10; 247 const int kSamplePercent = 10;
250 248
251 notification->set_progress(kSamplePercent); 249 notification->set_progress(kSamplePercent);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 bridge->Display(NotificationCommon::PERSISTENT, "notification_id2", 411 bridge->Display(NotificationCommon::PERSISTENT, "notification_id2",
414 "profile_id", false, *alert); 412 "profile_id", false, *alert);
415 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); 413 EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]);
416 EXPECT_EQ(1u, [[alert_dispatcher() alerts] count]); 414 EXPECT_EQ(1u, [[alert_dispatcher() alerts] count]);
417 } 415 }
418 416
419 // The destructor of the bridge should close all notifications. 417 // The destructor of the bridge should close all notifications.
420 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); 418 EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]);
421 EXPECT_EQ(0u, [[alert_dispatcher() alerts] count]); 419 EXPECT_EQ(0u, [[alert_dispatcher() alerts] count]);
422 } 420 }
421
422 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayETLDPlusOne) {
423 std::unique_ptr<Notification> notification =
424 CreateBanner("Title", "Context", "https://hello.world.test.co.uk",
425 "Button 1", nullptr);
426
427 std::unique_ptr<NotificationPlatformBridgeMac> bridge(
428 new NotificationPlatformBridgeMac(notification_center(),
429 alert_dispatcher()));
430 bridge->Display(NotificationCommon::PERSISTENT, "notification_id1",
431 "profile_id", false, *notification);
432
433 notification = CreateBanner("Title", "Context", "https://mail.appspot.com",
434 "Button 1", nullptr);
435
436 bridge->Display(NotificationCommon::PERSISTENT, "notification_id2",
437 "profile_id", false, *notification);
438 notification = CreateBanner("Title", "Context", "https://tests.peter.sh",
439 "Button 1", nullptr);
440
441 bridge->Display(NotificationCommon::PERSISTENT, "notification_id3",
442 "profile_id", false, *notification);
443
444 notification = CreateBanner("Title", "Context", "http://localhost:8080",
445 "Button 1", nullptr);
446
447 bridge->Display(NotificationCommon::PERSISTENT, "notification_id4",
448 "profile_id", false, *notification);
449
450 notification = CreateBanner("Title", "Context", "https://93.186.186.172",
451 "Button 1", nullptr);
452
453 bridge->Display(NotificationCommon::PERSISTENT, "notification_id5",
454 "profile_id", false, *notification);
455
456 NSArray* notifications = [notification_center() deliveredNotifications];
457 EXPECT_EQ(5u, [notifications count]);
458 NSUserNotification* delivered_notification = [notifications objectAtIndex:0];
459 EXPECT_NSEQ(@"test.co.uk", [delivered_notification subtitle]);
460 delivered_notification = [notifications objectAtIndex:1];
461 EXPECT_NSEQ(@"mail.appspot.com", [delivered_notification subtitle]);
462 delivered_notification = [notifications objectAtIndex:2];
463 EXPECT_NSEQ(@"peter.sh", [delivered_notification subtitle]);
464 delivered_notification = [notifications objectAtIndex:3];
465 EXPECT_NSEQ(@"localhost:8080", [delivered_notification subtitle]);
466 delivered_notification = [notifications objectAtIndex:4];
467 EXPECT_NSEQ(@"93.186.186.172", [delivered_notification subtitle]);
468 }
OLDNEW
« no previous file with comments | « chrome/browser/notifications/notification_platform_bridge_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698