| 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 | 6 |
| 7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" | 8 #include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" |
| 9 #include "chrome/browser/ui/cocoa/notifications/notification_constants_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" | 10 #include "chrome/browser/ui/cocoa/notifications/notification_response_builder_ma
c.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 TEST(NotificationResponseBuilderMacTest, TestNotificationClick) { | 13 TEST(NotificationResponseBuilderMacTest, TestNotificationClick) { |
| 14 base::scoped_nsobject<NotificationBuilder> builder( | 14 base::scoped_nsobject<NotificationBuilder> builder( |
| 15 [[NotificationBuilder alloc] init]); | 15 [[NotificationBuilder alloc] init]); |
| 16 [builder setTitle:@"Title"]; | 16 [builder setTitle:@"Title"]; |
| 17 [builder setSubTitle:@"https://www.miguel.com"]; | 17 [builder setSubTitle:@"https://www.miguel.com"]; |
| 18 [builder setContextMessage:@""]; | 18 [builder setContextMessage:@""]; |
| 19 [builder setTag:@"tag1"]; | 19 [builder setTag:@"tag1"]; |
| 20 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; | 20 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
| 21 [builder setNotificationId:@"notificationId"]; | 21 [builder setNotificationId:@"notificationId"]; |
| 22 [builder setProfileId:@"profileId"]; | 22 [builder setProfileId:@"profileId"]; |
| 23 [builder setIncognito:false]; | 23 [builder setIncognito:false]; |
| 24 [builder setNotificationType:[NSNumber numberWithInt:0]]; |
| 24 | 25 |
| 25 NSUserNotification* notification = [builder buildUserNotification]; | 26 NSUserNotification* notification = [builder buildUserNotification]; |
| 26 NSDictionary* response = | 27 NSDictionary* response = |
| 27 [NotificationResponseBuilder buildDictionary:notification]; | 28 [NotificationResponseBuilder buildDictionary:notification]; |
| 28 | 29 |
| 29 NSNumber* operation = | 30 NSNumber* operation = |
| 30 [response objectForKey:notification_constants::kNotificationOperation]; | 31 [response objectForKey:notification_constants::kNotificationOperation]; |
| 31 NSNumber* buttonIndex = | 32 NSNumber* buttonIndex = |
| 32 [response objectForKey:notification_constants::kNotificationButtonIndex]; | 33 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
| 33 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue); | 34 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue); |
| 34 EXPECT_EQ(-1, buttonIndex.intValue); | 35 EXPECT_EQ(-1, buttonIndex.intValue); |
| 35 } | 36 } |
| 36 | 37 |
| 37 TEST(NotificationResponseBuilderMacTest, TestNotificationSettingsClick) { | 38 TEST(NotificationResponseBuilderMacTest, TestNotificationSettingsClick) { |
| 38 base::scoped_nsobject<NotificationBuilder> builder( | 39 base::scoped_nsobject<NotificationBuilder> builder( |
| 39 [[NotificationBuilder alloc] init]); | 40 [[NotificationBuilder alloc] init]); |
| 40 [builder setTitle:@"Title"]; | 41 [builder setTitle:@"Title"]; |
| 41 [builder setSubTitle:@"https://www.miguel.com"]; | 42 [builder setSubTitle:@"https://www.miguel.com"]; |
| 42 [builder setContextMessage:@""]; | 43 [builder setContextMessage:@""]; |
| 43 [builder setTag:@"tag1"]; | 44 [builder setTag:@"tag1"]; |
| 44 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; | 45 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
| 45 [builder setNotificationId:@"notificationId"]; | 46 [builder setNotificationId:@"notificationId"]; |
| 46 [builder setProfileId:@"profileId"]; | 47 [builder setProfileId:@"profileId"]; |
| 47 [builder setIncognito:false]; | 48 [builder setIncognito:false]; |
| 49 [builder setNotificationType:[NSNumber numberWithInt:0]]; |
| 48 | 50 |
| 49 NSUserNotification* notification = [builder buildUserNotification]; | 51 NSUserNotification* notification = [builder buildUserNotification]; |
| 50 | 52 |
| 51 // This will be set by the notification center to indicate the only available | 53 // This will be set by the notification center to indicate the only available |
| 52 // button was clicked. | 54 // button was clicked. |
| 53 [notification | 55 [notification |
| 54 setValue: | 56 setValue: |
| 55 [NSNumber | 57 [NSNumber |
| 56 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] | 58 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] |
| 57 forKey:@"_activationType"]; | 59 forKey:@"_activationType"]; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 71 [[NotificationBuilder alloc] init]); | 73 [[NotificationBuilder alloc] init]); |
| 72 [builder setTitle:@"Title"]; | 74 [builder setTitle:@"Title"]; |
| 73 [builder setSubTitle:@"https://www.miguel.com"]; | 75 [builder setSubTitle:@"https://www.miguel.com"]; |
| 74 [builder setContextMessage:@""]; | 76 [builder setContextMessage:@""]; |
| 75 [builder setButtons:@"Button1" secondaryButton:@""]; | 77 [builder setButtons:@"Button1" secondaryButton:@""]; |
| 76 [builder setTag:@"tag1"]; | 78 [builder setTag:@"tag1"]; |
| 77 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; | 79 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
| 78 [builder setNotificationId:@"notificationId"]; | 80 [builder setNotificationId:@"notificationId"]; |
| 79 [builder setProfileId:@"profileId"]; | 81 [builder setProfileId:@"profileId"]; |
| 80 [builder setIncognito:false]; | 82 [builder setIncognito:false]; |
| 83 [builder setNotificationType:[NSNumber numberWithInt:0]]; |
| 81 | 84 |
| 82 NSUserNotification* notification = [builder buildUserNotification]; | 85 NSUserNotification* notification = [builder buildUserNotification]; |
| 83 | 86 |
| 84 // These values will be set by the notification center to indicate that button | 87 // These values will be set by the notification center to indicate that button |
| 85 // 1 was clicked. | 88 // 1 was clicked. |
| 86 [notification | 89 [notification |
| 87 setValue: | 90 setValue: |
| 88 [NSNumber | 91 [NSNumber |
| 89 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] | 92 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] |
| 90 forKey:@"_activationType"]; | 93 forKey:@"_activationType"]; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 106 [[NotificationBuilder alloc] init]); | 109 [[NotificationBuilder alloc] init]); |
| 107 [builder setTitle:@"Title"]; | 110 [builder setTitle:@"Title"]; |
| 108 [builder setSubTitle:@"https://www.miguel.com"]; | 111 [builder setSubTitle:@"https://www.miguel.com"]; |
| 109 [builder setContextMessage:@""]; | 112 [builder setContextMessage:@""]; |
| 110 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; | 113 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; |
| 111 [builder setTag:@"tag1"]; | 114 [builder setTag:@"tag1"]; |
| 112 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; | 115 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
| 113 [builder setNotificationId:@"notificationId"]; | 116 [builder setNotificationId:@"notificationId"]; |
| 114 [builder setProfileId:@"profileId"]; | 117 [builder setProfileId:@"profileId"]; |
| 115 [builder setIncognito:false]; | 118 [builder setIncognito:false]; |
| 119 [builder setNotificationType:[NSNumber numberWithInt:0]]; |
| 116 | 120 |
| 117 NSUserNotification* notification = [builder buildUserNotification]; | 121 NSUserNotification* notification = [builder buildUserNotification]; |
| 118 | 122 |
| 119 // These values will be set by the notification center to indicate that button | 123 // These values will be set by the notification center to indicate that button |
| 120 // 2 was clicked. | 124 // 2 was clicked. |
| 121 [notification | 125 [notification |
| 122 setValue: | 126 setValue: |
| 123 [NSNumber | 127 [NSNumber |
| 124 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] | 128 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] |
| 125 forKey:@"_activationType"]; | 129 forKey:@"_activationType"]; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 143 [[NotificationBuilder alloc] init]); | 147 [[NotificationBuilder alloc] init]); |
| 144 [builder setTitle:@"Title"]; | 148 [builder setTitle:@"Title"]; |
| 145 [builder setSubTitle:@"https://www.miguel.com"]; | 149 [builder setSubTitle:@"https://www.miguel.com"]; |
| 146 [builder setContextMessage:@""]; | 150 [builder setContextMessage:@""]; |
| 147 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; | 151 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; |
| 148 [builder setTag:@"tag1"]; | 152 [builder setTag:@"tag1"]; |
| 149 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; | 153 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
| 150 [builder setNotificationId:@"notificationId"]; | 154 [builder setNotificationId:@"notificationId"]; |
| 151 [builder setProfileId:@"profileId"]; | 155 [builder setProfileId:@"profileId"]; |
| 152 [builder setIncognito:false]; | 156 [builder setIncognito:false]; |
| 157 [builder setNotificationType:[NSNumber numberWithInt:0]]; |
| 153 | 158 |
| 154 NSUserNotification* notification = [builder buildUserNotification]; | 159 NSUserNotification* notification = [builder buildUserNotification]; |
| 155 | 160 |
| 156 // These values will be set by the notification center to indicate that button | 161 // These values will be set by the notification center to indicate that button |
| 157 // 2 was clicked. | 162 // 2 was clicked. |
| 158 [notification | 163 [notification |
| 159 setValue: | 164 setValue: |
| 160 [NSNumber | 165 [NSNumber |
| 161 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] | 166 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] |
| 162 forKey:@"_activationType"]; | 167 forKey:@"_activationType"]; |
| 163 [notification setValue:[NSNumber numberWithInt:2] | 168 [notification setValue:[NSNumber numberWithInt:2] |
| 164 forKey:@"_alternateActionIndex"]; | 169 forKey:@"_alternateActionIndex"]; |
| 165 | 170 |
| 166 NSDictionary* response = | 171 NSDictionary* response = |
| 167 [NotificationResponseBuilder buildDictionary:notification]; | 172 [NotificationResponseBuilder buildDictionary:notification]; |
| 168 | 173 |
| 169 NSNumber* operation = | 174 NSNumber* operation = |
| 170 [response objectForKey:notification_constants::kNotificationOperation]; | 175 [response objectForKey:notification_constants::kNotificationOperation]; |
| 171 NSNumber* buttonIndex = | 176 NSNumber* buttonIndex = |
| 172 [response objectForKey:notification_constants::kNotificationButtonIndex]; | 177 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
| 173 EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue); | 178 EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue); |
| 174 EXPECT_EQ(-1, buttonIndex.intValue); | 179 EXPECT_EQ(-1, buttonIndex.intValue); |
| 175 } | 180 } |
| OLD | NEW |