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

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

Issue 2799343003: Add support for native extension notifications (Closed)
Patch Set: Remove dependent CL to land standalone 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
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/notifications/notification_common.h"
9 #include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" 9 #include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h"
10 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" 10 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h"
11 #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"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 class NotificationResponseBuilderMacTest : public testing::Test { 14 class NotificationResponseBuilderMacTest : public testing::Test {
15 protected: 15 protected:
16 base::scoped_nsobject<NotificationBuilder> NewTestBuilder() { 16 base::scoped_nsobject<NotificationBuilder> NewTestBuilder(
17 NotificationCommon::Type type) {
17 base::scoped_nsobject<NotificationBuilder> builder( 18 base::scoped_nsobject<NotificationBuilder> builder(
18 [[NotificationBuilder alloc] initWithCloseLabel:@"Close" 19 [[NotificationBuilder alloc] initWithCloseLabel:@"Close"
19 optionsLabel:@"Options" 20 optionsLabel:@"Options"
20 settingsLabel:@"Settings"]); 21 settingsLabel:@"Settings"]);
21 [builder setTitle:@"Title"]; 22 [builder setTitle:@"Title"];
22 [builder setSubTitle:@"https://www.miguel.com"]; 23 [builder setSubTitle:@"https://www.miguel.com"];
23 [builder setContextMessage:@""]; 24 [builder setContextMessage:@""];
24 [builder setTag:@"tag1"]; 25 [builder setTag:@"tag1"];
25 [builder setIcon:[NSImage imageNamed:NSImageNameApplicationIcon]]; 26 [builder setIcon:[NSImage imageNamed:NSImageNameApplicationIcon]];
26 [builder setNotificationId:@"notificationId"]; 27 [builder setNotificationId:@"notificationId"];
27 [builder setProfileId:@"profileId"]; 28 [builder setProfileId:@"profileId"];
28 [builder setIncognito:false]; 29 [builder setIncognito:false];
29 [builder setNotificationType:@(NotificationCommon::PERSISTENT)]; 30 [builder setNotificationType:@(type)];
31 [builder setShowSettingsButton:(type != NotificationCommon::EXTENSION)];
30 return builder; 32 return builder;
31 } 33 }
32 }; 34 };
33 35
34 TEST_F(NotificationResponseBuilderMacTest, TestNotificationClick) { 36 TEST_F(NotificationResponseBuilderMacTest, TestNotificationClick) {
35 base::scoped_nsobject<NotificationBuilder> builder = NewTestBuilder(); 37 base::scoped_nsobject<NotificationBuilder> builder =
38 NewTestBuilder(NotificationCommon::PERSISTENT);
36 NSUserNotification* notification = [builder buildUserNotification]; 39 NSUserNotification* notification = [builder buildUserNotification];
37 // This will be set by the notification center to indicate the notification 40 // This will be set by the notification center to indicate the notification
38 // was clicked. 41 // was clicked.
39 [notification setValue:@(NSUserNotificationActivationTypeContentsClicked) 42 [notification setValue:@(NSUserNotificationActivationTypeContentsClicked)
40 forKey:@"_activationType"]; 43 forKey:@"_activationType"];
41 44
42 NSDictionary* response = 45 NSDictionary* response =
43 [NotificationResponseBuilder buildDictionary:notification]; 46 [NotificationResponseBuilder buildDictionary:notification];
44 47
45 NSNumber* operation = 48 NSNumber* operation =
46 [response objectForKey:notification_constants::kNotificationOperation]; 49 [response objectForKey:notification_constants::kNotificationOperation];
47 NSNumber* buttonIndex = 50 NSNumber* buttonIndex =
48 [response objectForKey:notification_constants::kNotificationButtonIndex]; 51 [response objectForKey:notification_constants::kNotificationButtonIndex];
52
49 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue); 53 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue);
50 EXPECT_EQ(-1, buttonIndex.intValue); 54 EXPECT_EQ(-1, buttonIndex.intValue);
51 } 55 }
52 56
53 TEST_F(NotificationResponseBuilderMacTest, TestNotificationSettingsClick) { 57 TEST_F(NotificationResponseBuilderMacTest, TestNotificationSettingsClick) {
54 base::scoped_nsobject<NotificationBuilder> builder = NewTestBuilder(); 58 base::scoped_nsobject<NotificationBuilder> builder =
59 NewTestBuilder(NotificationCommon::PERSISTENT);
55 NSUserNotification* notification = [builder buildUserNotification]; 60 NSUserNotification* notification = [builder buildUserNotification];
56 61
57 // This will be set by the notification center to indicate the only available 62 // This will be set by the notification center to indicate the only available
58 // button was clicked. 63 // button was clicked.
59 [notification setValue:@(NSUserNotificationActivationTypeActionButtonClicked) 64 [notification setValue:@(NSUserNotificationActivationTypeActionButtonClicked)
60 forKey:@"_activationType"]; 65 forKey:@"_activationType"];
61 NSDictionary* response = 66 NSDictionary* response =
62 [NotificationResponseBuilder buildDictionary:notification]; 67 [NotificationResponseBuilder buildDictionary:notification];
63 68
64 NSNumber* operation = 69 NSNumber* operation =
65 [response objectForKey:notification_constants::kNotificationOperation]; 70 [response objectForKey:notification_constants::kNotificationOperation];
66 NSNumber* buttonIndex = 71 NSNumber* buttonIndex =
67 [response objectForKey:notification_constants::kNotificationButtonIndex]; 72 [response objectForKey:notification_constants::kNotificationButtonIndex];
73
68 EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue); 74 EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue);
69 EXPECT_EQ(-1, buttonIndex.intValue); 75 EXPECT_EQ(-1, buttonIndex.intValue);
70 } 76 }
71 77
72 TEST_F(NotificationResponseBuilderMacTest, TestNotificationOneActionClick) { 78 TEST_F(NotificationResponseBuilderMacTest, TestNotificationOneActionClick) {
73 base::scoped_nsobject<NotificationBuilder> builder = NewTestBuilder(); 79 base::scoped_nsobject<NotificationBuilder> builder =
80 NewTestBuilder(NotificationCommon::PERSISTENT);
74 [builder setButtons:@"Button1" secondaryButton:@""]; 81 [builder setButtons:@"Button1" secondaryButton:@""];
75 82
76 NSUserNotification* notification = [builder buildUserNotification]; 83 NSUserNotification* notification = [builder buildUserNotification];
77 84
78 // These values will be set by the notification center to indicate that button 85 // These values will be set by the notification center to indicate that button
79 // 1 was clicked. 86 // 1 was clicked.
80 [notification setValue:@(NSUserNotificationActivationTypeActionButtonClicked) 87 [notification setValue:@(NSUserNotificationActivationTypeActionButtonClicked)
81 forKey:@"_activationType"]; 88 forKey:@"_activationType"];
82 [notification setValue:[NSNumber numberWithInt:0] 89 [notification setValue:[NSNumber numberWithInt:0]
83 forKey:@"_alternateActionIndex"]; 90 forKey:@"_alternateActionIndex"];
84 NSDictionary* response = 91 NSDictionary* response =
85 [NotificationResponseBuilder buildDictionary:notification]; 92 [NotificationResponseBuilder buildDictionary:notification];
86 93
87 NSNumber* operation = 94 NSNumber* operation =
88 [response objectForKey:notification_constants::kNotificationOperation]; 95 [response objectForKey:notification_constants::kNotificationOperation];
89 NSNumber* buttonIndex = 96 NSNumber* buttonIndex =
90 [response objectForKey:notification_constants::kNotificationButtonIndex]; 97 [response objectForKey:notification_constants::kNotificationButtonIndex];
91 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue); 98 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue);
92 EXPECT_EQ(0, buttonIndex.intValue); 99 EXPECT_EQ(0, buttonIndex.intValue);
93 } 100 }
94 101
95 TEST_F(NotificationResponseBuilderMacTest, TestNotificationTwoActionClick) { 102 TEST_F(NotificationResponseBuilderMacTest, TestNotificationTwoActionClick) {
96 base::scoped_nsobject<NotificationBuilder> builder = NewTestBuilder(); 103 base::scoped_nsobject<NotificationBuilder> builder =
104 NewTestBuilder(NotificationCommon::PERSISTENT);
97 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; 105 [builder setButtons:@"Button1" secondaryButton:@"Button2"];
98 106
99 NSUserNotification* notification = [builder buildUserNotification]; 107 NSUserNotification* notification = [builder buildUserNotification];
100 108
101 // These values will be set by the notification center to indicate that button 109 // These values will be set by the notification center to indicate that button
102 // 2 was clicked. 110 // 2 was clicked.
103 [notification setValue:@(NSUserNotificationActivationTypeActionButtonClicked) 111 [notification setValue:@(NSUserNotificationActivationTypeActionButtonClicked)
104 forKey:@"_activationType"]; 112 forKey:@"_activationType"];
105 [notification setValue:[NSNumber numberWithInt:1] 113 [notification setValue:[NSNumber numberWithInt:1]
106 forKey:@"_alternateActionIndex"]; 114 forKey:@"_alternateActionIndex"];
107 115
108 NSDictionary* response = 116 NSDictionary* response =
109 [NotificationResponseBuilder buildDictionary:notification]; 117 [NotificationResponseBuilder buildDictionary:notification];
110 118
111 NSNumber* operation = 119 NSNumber* operation =
112 [response objectForKey:notification_constants::kNotificationOperation]; 120 [response objectForKey:notification_constants::kNotificationOperation];
113 NSNumber* buttonIndex = 121 NSNumber* buttonIndex =
114 [response objectForKey:notification_constants::kNotificationButtonIndex]; 122 [response objectForKey:notification_constants::kNotificationButtonIndex];
115 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue); 123 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue);
116 EXPECT_EQ(1, buttonIndex.intValue); 124 EXPECT_EQ(1, buttonIndex.intValue);
117 } 125 }
118 126
119 TEST_F(NotificationResponseBuilderMacTest, 127 TEST_F(NotificationResponseBuilderMacTest,
120 TestNotificationTwoActionSettingsClick) { 128 TestNotificationTwoActionSettingsClick) {
121 base::scoped_nsobject<NotificationBuilder> builder = NewTestBuilder(); 129 base::scoped_nsobject<NotificationBuilder> builder =
130 NewTestBuilder(NotificationCommon::PERSISTENT);
122 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; 131 [builder setButtons:@"Button1" secondaryButton:@"Button2"];
123 NSUserNotification* notification = [builder buildUserNotification]; 132 NSUserNotification* notification = [builder buildUserNotification];
124 133
125 // These values will be set by the notification center to indicate that button 134 // These values will be set by the notification center to indicate that button
126 // 2 was clicked. 135 // 2 was clicked.
127 [notification 136 [notification
128 setValue: 137 setValue:
129 [NSNumber 138 [NSNumber
130 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] 139 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked]
131 forKey:@"_activationType"]; 140 forKey:@"_activationType"];
132 [notification setValue:[NSNumber numberWithInt:2] 141 [notification setValue:[NSNumber numberWithInt:2]
133 forKey:@"_alternateActionIndex"]; 142 forKey:@"_alternateActionIndex"];
134 143
135 NSDictionary* response = 144 NSDictionary* response =
136 [NotificationResponseBuilder buildDictionary:notification]; 145 [NotificationResponseBuilder buildDictionary:notification];
137 146
138 NSNumber* operation = 147 NSNumber* operation =
139 [response objectForKey:notification_constants::kNotificationOperation]; 148 [response objectForKey:notification_constants::kNotificationOperation];
140 NSNumber* buttonIndex = 149 NSNumber* buttonIndex =
141 [response objectForKey:notification_constants::kNotificationButtonIndex]; 150 [response objectForKey:notification_constants::kNotificationButtonIndex];
142 EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue); 151 EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue);
143 EXPECT_EQ(-1, buttonIndex.intValue); 152 EXPECT_EQ(-1, buttonIndex.intValue);
144 } 153 }
145 154
146 TEST_F(NotificationResponseBuilderMacTest, TestNotificationClose) { 155 TEST_F(NotificationResponseBuilderMacTest, TestNotificationClose) {
147 base::scoped_nsobject<NotificationBuilder> builder = NewTestBuilder(); 156 base::scoped_nsobject<NotificationBuilder> builder =
157 NewTestBuilder(NotificationCommon::PERSISTENT);
148 NSUserNotification* notification = [builder buildUserNotification]; 158 NSUserNotification* notification = [builder buildUserNotification];
149 159
150 // None is what the NSUserNotification center emits when closing since it 160 // None is what the NSUserNotification center emits when closing since it
151 // interprets it as not activated. 161 // interprets it as not activated.
152 [notification setValue:@(NSUserNotificationActivationTypeNone) 162 [notification setValue:@(NSUserNotificationActivationTypeNone)
153 forKey:@"_activationType"]; 163 forKey:@"_activationType"];
154 164
155 NSDictionary* response = 165 NSDictionary* response =
156 [NotificationResponseBuilder buildDictionary:notification]; 166 [NotificationResponseBuilder buildDictionary:notification];
157 167
158 NSNumber* operation = 168 NSNumber* operation =
159 [response objectForKey:notification_constants::kNotificationOperation]; 169 [response objectForKey:notification_constants::kNotificationOperation];
160 NSNumber* buttonIndex = 170 NSNumber* buttonIndex =
161 [response objectForKey:notification_constants::kNotificationButtonIndex]; 171 [response objectForKey:notification_constants::kNotificationButtonIndex];
162 EXPECT_EQ(1 /* NOTIFICATION_CLOSE */, operation.intValue); 172 EXPECT_EQ(1 /* NOTIFICATION_CLOSE */, operation.intValue);
163 EXPECT_EQ(-1, buttonIndex.intValue); 173 EXPECT_EQ(-1, buttonIndex.intValue);
164 } 174 }
175
176 TEST_F(NotificationResponseBuilderMacTest, TestNotificationExtension) {
177 base::scoped_nsobject<NotificationBuilder> builder =
178 NewTestBuilder(NotificationCommon::EXTENSION);
179 [builder setButtons:@"Button1" secondaryButton:@"Button2"];
180 NSUserNotification* notification = [builder buildUserNotification];
181 // These values will be set by the notification center to indicate that button
182 // 1 was clicked.
183 [notification
184 setValue:
185 [NSNumber
186 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked]
187 forKey:@"_activationType"];
188 [notification setValue:[NSNumber numberWithInt:1]
189 forKey:@"_alternateActionIndex"];
190
191 NSDictionary* response =
192 [NotificationResponseBuilder buildDictionary:notification];
193
194 NSNumber* operation =
195 [response objectForKey:notification_constants::kNotificationOperation];
196 NSNumber* buttonIndex =
197 [response objectForKey:notification_constants::kNotificationButtonIndex];
198 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue);
199 EXPECT_EQ(1, buttonIndex.intValue);
200 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698