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

Side by Side Diff: chrome/browser/ui/cocoa/notifications/notification_response_builder_mac_unittest.mm

Issue 2093953002: Introduce a new API to handle native notification clicks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 5 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
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 6
7 #include "base/mac/scoped_nsobject.h" 7 #include "base/mac/scoped_nsobject.h"
8 #include "chrome/browser/notifications/notification_common.h"
8 #include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" 9 #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_constants_mac.h"
10 #include "chrome/browser/ui/cocoa/notifications/notification_response_builder_ma c.h" 11 #include "chrome/browser/ui/cocoa/notifications/notification_response_builder_ma c.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 TEST(NotificationResponseBuilderMacTest, TestNotificationClick) { 14 TEST(NotificationResponseBuilderMacTest, TestNotificationClick) {
14 base::scoped_nsobject<NotificationBuilder> builder( 15 base::scoped_nsobject<NotificationBuilder> builder(
15 [[NotificationBuilder alloc] init]); 16 [[NotificationBuilder alloc] init]);
16 [builder setTitle:@"Title"]; 17 [builder setTitle:@"Title"];
17 [builder setSubTitle:@"https://www.miguel.com"]; 18 [builder setSubTitle:@"https://www.miguel.com"];
18 [builder setContextMessage:@""]; 19 [builder setContextMessage:@""];
19 [builder setTag:@"tag1"]; 20 [builder setTag:@"tag1"];
20 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; 21 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]];
21 [builder setNotificationId:@"notificationId"]; 22 [builder setNotificationId:@"notificationId"];
22 [builder setProfileId:@"profileId"]; 23 [builder setProfileId:@"profileId"];
23 [builder setIncognito:false]; 24 [builder setIncognito:false];
25 [builder
26 setNotificationType:[NSNumber
27 numberWithInt:NotificationCommon::PERSISTENT]];
24 28
25 NSUserNotification* notification = [builder buildUserNotification]; 29 NSUserNotification* notification = [builder buildUserNotification];
26 NSDictionary* response = 30 NSDictionary* response =
27 [NotificationResponseBuilder buildDictionary:notification]; 31 [NotificationResponseBuilder buildDictionary:notification];
28 32
29 NSNumber* operation = 33 NSNumber* operation =
30 [response objectForKey:notification_constants::kNotificationOperation]; 34 [response objectForKey:notification_constants::kNotificationOperation];
31 NSNumber* buttonIndex = 35 NSNumber* buttonIndex =
32 [response objectForKey:notification_constants::kNotificationButtonIndex]; 36 [response objectForKey:notification_constants::kNotificationButtonIndex];
33 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue); 37 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue);
34 EXPECT_EQ(-1, buttonIndex.intValue); 38 EXPECT_EQ(-1, buttonIndex.intValue);
35 } 39 }
36 40
37 TEST(NotificationResponseBuilderMacTest, TestNotificationSettingsClick) { 41 TEST(NotificationResponseBuilderMacTest, TestNotificationSettingsClick) {
38 base::scoped_nsobject<NotificationBuilder> builder( 42 base::scoped_nsobject<NotificationBuilder> builder(
39 [[NotificationBuilder alloc] init]); 43 [[NotificationBuilder alloc] init]);
40 [builder setTitle:@"Title"]; 44 [builder setTitle:@"Title"];
41 [builder setSubTitle:@"https://www.miguel.com"]; 45 [builder setSubTitle:@"https://www.miguel.com"];
42 [builder setContextMessage:@""]; 46 [builder setContextMessage:@""];
43 [builder setTag:@"tag1"]; 47 [builder setTag:@"tag1"];
44 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; 48 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]];
45 [builder setNotificationId:@"notificationId"]; 49 [builder setNotificationId:@"notificationId"];
46 [builder setProfileId:@"profileId"]; 50 [builder setProfileId:@"profileId"];
47 [builder setIncognito:false]; 51 [builder setIncognito:false];
52 [builder
53 setNotificationType:[NSNumber
54 numberWithInt:NotificationCommon::PERSISTENT]];
48 55
49 NSUserNotification* notification = [builder buildUserNotification]; 56 NSUserNotification* notification = [builder buildUserNotification];
50 57
51 // This will be set by the notification center to indicate the only available 58 // This will be set by the notification center to indicate the only available
52 // button was clicked. 59 // button was clicked.
53 [notification 60 [notification
54 setValue: 61 setValue:
55 [NSNumber 62 [NSNumber
56 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] 63 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked]
57 forKey:@"_activationType"]; 64 forKey:@"_activationType"];
(...skipping 13 matching lines...) Expand all
71 [[NotificationBuilder alloc] init]); 78 [[NotificationBuilder alloc] init]);
72 [builder setTitle:@"Title"]; 79 [builder setTitle:@"Title"];
73 [builder setSubTitle:@"https://www.miguel.com"]; 80 [builder setSubTitle:@"https://www.miguel.com"];
74 [builder setContextMessage:@""]; 81 [builder setContextMessage:@""];
75 [builder setButtons:@"Button1" secondaryButton:@""]; 82 [builder setButtons:@"Button1" secondaryButton:@""];
76 [builder setTag:@"tag1"]; 83 [builder setTag:@"tag1"];
77 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; 84 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]];
78 [builder setNotificationId:@"notificationId"]; 85 [builder setNotificationId:@"notificationId"];
79 [builder setProfileId:@"profileId"]; 86 [builder setProfileId:@"profileId"];
80 [builder setIncognito:false]; 87 [builder setIncognito:false];
88 [builder
89 setNotificationType:[NSNumber
90 numberWithInt:NotificationCommon::PERSISTENT]];
81 91
82 NSUserNotification* notification = [builder buildUserNotification]; 92 NSUserNotification* notification = [builder buildUserNotification];
83 93
84 // These values will be set by the notification center to indicate that button 94 // These values will be set by the notification center to indicate that button
85 // 1 was clicked. 95 // 1 was clicked.
86 [notification 96 [notification
87 setValue: 97 setValue:
88 [NSNumber 98 [NSNumber
89 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] 99 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked]
90 forKey:@"_activationType"]; 100 forKey:@"_activationType"];
(...skipping 15 matching lines...) Expand all
106 [[NotificationBuilder alloc] init]); 116 [[NotificationBuilder alloc] init]);
107 [builder setTitle:@"Title"]; 117 [builder setTitle:@"Title"];
108 [builder setSubTitle:@"https://www.miguel.com"]; 118 [builder setSubTitle:@"https://www.miguel.com"];
109 [builder setContextMessage:@""]; 119 [builder setContextMessage:@""];
110 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; 120 [builder setButtons:@"Button1" secondaryButton:@"Button2"];
111 [builder setTag:@"tag1"]; 121 [builder setTag:@"tag1"];
112 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; 122 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]];
113 [builder setNotificationId:@"notificationId"]; 123 [builder setNotificationId:@"notificationId"];
114 [builder setProfileId:@"profileId"]; 124 [builder setProfileId:@"profileId"];
115 [builder setIncognito:false]; 125 [builder setIncognito:false];
126 [builder
127 setNotificationType:[NSNumber
128 numberWithInt:NotificationCommon::PERSISTENT]];
116 129
117 NSUserNotification* notification = [builder buildUserNotification]; 130 NSUserNotification* notification = [builder buildUserNotification];
118 131
119 // These values will be set by the notification center to indicate that button 132 // These values will be set by the notification center to indicate that button
120 // 2 was clicked. 133 // 2 was clicked.
121 [notification 134 [notification
122 setValue: 135 setValue:
123 [NSNumber 136 [NSNumber
124 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] 137 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked]
125 forKey:@"_activationType"]; 138 forKey:@"_activationType"];
(...skipping 17 matching lines...) Expand all
143 [[NotificationBuilder alloc] init]); 156 [[NotificationBuilder alloc] init]);
144 [builder setTitle:@"Title"]; 157 [builder setTitle:@"Title"];
145 [builder setSubTitle:@"https://www.miguel.com"]; 158 [builder setSubTitle:@"https://www.miguel.com"];
146 [builder setContextMessage:@""]; 159 [builder setContextMessage:@""];
147 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; 160 [builder setButtons:@"Button1" secondaryButton:@"Button2"];
148 [builder setTag:@"tag1"]; 161 [builder setTag:@"tag1"];
149 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; 162 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]];
150 [builder setNotificationId:@"notificationId"]; 163 [builder setNotificationId:@"notificationId"];
151 [builder setProfileId:@"profileId"]; 164 [builder setProfileId:@"profileId"];
152 [builder setIncognito:false]; 165 [builder setIncognito:false];
166 [builder
167 setNotificationType:[NSNumber
168 numberWithInt:NotificationCommon::PERSISTENT]];
153 169
154 NSUserNotification* notification = [builder buildUserNotification]; 170 NSUserNotification* notification = [builder buildUserNotification];
155 171
156 // These values will be set by the notification center to indicate that button 172 // These values will be set by the notification center to indicate that button
157 // 2 was clicked. 173 // 2 was clicked.
158 [notification 174 [notification
159 setValue: 175 setValue:
160 [NSNumber 176 [NSNumber
161 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] 177 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked]
162 forKey:@"_activationType"]; 178 forKey:@"_activationType"];
163 [notification setValue:[NSNumber numberWithInt:2] 179 [notification setValue:[NSNumber numberWithInt:2]
164 forKey:@"_alternateActionIndex"]; 180 forKey:@"_alternateActionIndex"];
165 181
166 NSDictionary* response = 182 NSDictionary* response =
167 [NotificationResponseBuilder buildDictionary:notification]; 183 [NotificationResponseBuilder buildDictionary:notification];
168 184
169 NSNumber* operation = 185 NSNumber* operation =
170 [response objectForKey:notification_constants::kNotificationOperation]; 186 [response objectForKey:notification_constants::kNotificationOperation];
171 NSNumber* buttonIndex = 187 NSNumber* buttonIndex =
172 [response objectForKey:notification_constants::kNotificationButtonIndex]; 188 [response objectForKey:notification_constants::kNotificationButtonIndex];
173 EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue); 189 EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue);
174 EXPECT_EQ(-1, buttonIndex.intValue); 190 EXPECT_EQ(-1, buttonIndex.intValue);
175 } 191 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/notifications/notification_response_builder_mac.mm ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698