OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import <AppKit/AppKit.h> |
| 6 |
| 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" |
| 9 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" |
| 10 #include "chrome/browser/ui/cocoa/notifications/notification_response_builder_ma
c.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 TEST(NotificationResponseBuilderMacTest, TestNotificationClick) { |
| 14 base::scoped_nsobject<NotificationBuilder> builder( |
| 15 [[NotificationBuilder alloc] init]); |
| 16 [builder setTitle:@"Title"]; |
| 17 [builder setSubTitle:@"https://www.miguel.com"]; |
| 18 [builder setContextMessage:@""]; |
| 19 [builder setTag:@"tag1"]; |
| 20 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
| 21 [builder setNotificationId:@"notificationId"]; |
| 22 [builder setProfileId:@"profileId"]; |
| 23 [builder setIncognito:false]; |
| 24 |
| 25 NSUserNotification* notification = [builder buildUserNotification]; |
| 26 NSDictionary* response = |
| 27 [NotificationResponseBuilder buildDictionary:notification]; |
| 28 |
| 29 NSNumber* operation = |
| 30 [response objectForKey:notification_constants::kNotificationOperation]; |
| 31 NSNumber* buttonIndex = |
| 32 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
| 33 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue); |
| 34 EXPECT_EQ(-1, buttonIndex.intValue); |
| 35 } |
| 36 |
| 37 TEST(NotificationResponseBuilderMacTest, TestNotificationSettingsClick) { |
| 38 base::scoped_nsobject<NotificationBuilder> builder( |
| 39 [[NotificationBuilder alloc] init]); |
| 40 [builder setTitle:@"Title"]; |
| 41 [builder setSubTitle:@"https://www.miguel.com"]; |
| 42 [builder setContextMessage:@""]; |
| 43 [builder setTag:@"tag1"]; |
| 44 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
| 45 [builder setNotificationId:@"notificationId"]; |
| 46 [builder setProfileId:@"profileId"]; |
| 47 [builder setIncognito:false]; |
| 48 |
| 49 NSUserNotification* notification = [builder buildUserNotification]; |
| 50 |
| 51 // This will be set by the notification center to indicate the only available |
| 52 // button was clicked. |
| 53 [notification |
| 54 setValue: |
| 55 [NSNumber |
| 56 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] |
| 57 forKey:@"_activationType"]; |
| 58 NSDictionary* response = |
| 59 [NotificationResponseBuilder buildDictionary:notification]; |
| 60 |
| 61 NSNumber* operation = |
| 62 [response objectForKey:notification_constants::kNotificationOperation]; |
| 63 NSNumber* buttonIndex = |
| 64 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
| 65 EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue); |
| 66 EXPECT_EQ(-1, buttonIndex.intValue); |
| 67 } |
| 68 |
| 69 TEST(NotificationResponseBuilderMacTest, TestNotificationOneActionClick) { |
| 70 base::scoped_nsobject<NotificationBuilder> builder( |
| 71 [[NotificationBuilder alloc] init]); |
| 72 [builder setTitle:@"Title"]; |
| 73 [builder setSubTitle:@"https://www.miguel.com"]; |
| 74 [builder setContextMessage:@""]; |
| 75 [builder setButtons:@"Button1" secondaryButton:@""]; |
| 76 [builder setTag:@"tag1"]; |
| 77 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
| 78 [builder setNotificationId:@"notificationId"]; |
| 79 [builder setProfileId:@"profileId"]; |
| 80 [builder setIncognito:false]; |
| 81 |
| 82 NSUserNotification* notification = [builder buildUserNotification]; |
| 83 |
| 84 // These values will be set by the notification center to indicate that button |
| 85 // 1 was clicked. |
| 86 [notification |
| 87 setValue: |
| 88 [NSNumber |
| 89 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] |
| 90 forKey:@"_activationType"]; |
| 91 [notification setValue:[NSNumber numberWithInt:0] |
| 92 forKey:@"_alternateActionIndex"]; |
| 93 NSDictionary* response = |
| 94 [NotificationResponseBuilder buildDictionary:notification]; |
| 95 |
| 96 NSNumber* operation = |
| 97 [response objectForKey:notification_constants::kNotificationOperation]; |
| 98 NSNumber* buttonIndex = |
| 99 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
| 100 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue); |
| 101 EXPECT_EQ(0, buttonIndex.intValue); |
| 102 } |
| 103 |
| 104 TEST(NotificationResponseBuilderMacTest, TestNotificationTwoActionClick) { |
| 105 base::scoped_nsobject<NotificationBuilder> builder( |
| 106 [[NotificationBuilder alloc] init]); |
| 107 [builder setTitle:@"Title"]; |
| 108 [builder setSubTitle:@"https://www.miguel.com"]; |
| 109 [builder setContextMessage:@""]; |
| 110 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; |
| 111 [builder setTag:@"tag1"]; |
| 112 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
| 113 [builder setNotificationId:@"notificationId"]; |
| 114 [builder setProfileId:@"profileId"]; |
| 115 [builder setIncognito:false]; |
| 116 |
| 117 NSUserNotification* notification = [builder buildUserNotification]; |
| 118 |
| 119 // These values will be set by the notification center to indicate that button |
| 120 // 2 was clicked. |
| 121 [notification |
| 122 setValue: |
| 123 [NSNumber |
| 124 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] |
| 125 forKey:@"_activationType"]; |
| 126 [notification setValue:[NSNumber numberWithInt:1] |
| 127 forKey:@"_alternateActionIndex"]; |
| 128 |
| 129 NSDictionary* response = |
| 130 [NotificationResponseBuilder buildDictionary:notification]; |
| 131 |
| 132 NSNumber* operation = |
| 133 [response objectForKey:notification_constants::kNotificationOperation]; |
| 134 NSNumber* buttonIndex = |
| 135 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
| 136 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue); |
| 137 EXPECT_EQ(1, buttonIndex.intValue); |
| 138 } |
| 139 |
| 140 TEST(NotificationResponseBuilderMacTest, |
| 141 TestNotificationTwoActionSettingsClick) { |
| 142 base::scoped_nsobject<NotificationBuilder> builder( |
| 143 [[NotificationBuilder alloc] init]); |
| 144 [builder setTitle:@"Title"]; |
| 145 [builder setSubTitle:@"https://www.miguel.com"]; |
| 146 [builder setContextMessage:@""]; |
| 147 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; |
| 148 [builder setTag:@"tag1"]; |
| 149 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
| 150 [builder setNotificationId:@"notificationId"]; |
| 151 [builder setProfileId:@"profileId"]; |
| 152 [builder setIncognito:false]; |
| 153 |
| 154 NSUserNotification* notification = [builder buildUserNotification]; |
| 155 |
| 156 // These values will be set by the notification center to indicate that button |
| 157 // 2 was clicked. |
| 158 [notification |
| 159 setValue: |
| 160 [NSNumber |
| 161 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] |
| 162 forKey:@"_activationType"]; |
| 163 [notification setValue:[NSNumber numberWithInt:2] |
| 164 forKey:@"_alternateActionIndex"]; |
| 165 |
| 166 NSDictionary* response = |
| 167 [NotificationResponseBuilder buildDictionary:notification]; |
| 168 |
| 169 NSNumber* operation = |
| 170 [response objectForKey:notification_constants::kNotificationOperation]; |
| 171 NSNumber* buttonIndex = |
| 172 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
| 173 EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue); |
| 174 EXPECT_EQ(-1, buttonIndex.intValue); |
| 175 } |
OLD | NEW |