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

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

Issue 2143613002: Add new tests to the Notification Mac Bridge Base URL: https://chromium.googlesource.com/chromium/src.git@unit_test
Patch Set: 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
« no previous file with comments | « chrome/browser/notifications/notification_platform_bridge_mac.h ('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 6
7 #include "base/mac/scoped_nsobject.h" 7 #include "base/mac/scoped_nsobject.h"
8 #include "chrome/browser/notifications/notification.h" 8 #include "chrome/browser/notifications/notification.h"
9 #include "chrome/browser/notifications/notification_platform_bridge_mac.h" 9 #include "chrome/browser/notifications/notification_platform_bridge_mac.h"
10 #include "chrome/browser/notifications/notification_test_util.h" 10 #include "chrome/browser/notifications/notification_test_util.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 NotificationPlatformBridgeMac* bridge = new NotificationPlatformBridgeMac( 125 NotificationPlatformBridgeMac* bridge = new NotificationPlatformBridgeMac(
126 notificationCenter, false /* set_delegate */); 126 notificationCenter, false /* set_delegate */);
127 [[notificationCenter expect] 127 [[notificationCenter expect]
128 deliverNotification:[OCMArg checkWithBlock:^BOOL(id toast) { 128 deliverNotification:[OCMArg checkWithBlock:^BOOL(id toast) {
129 return [[toast title] isEqualToString:@"Title"] && 129 return [[toast title] isEqualToString:@"Title"] &&
130 [[toast informativeText] isEqualToString:@"Context"] && 130 [[toast informativeText] isEqualToString:@"Context"] &&
131 [[toast subtitle] isEqualToString:@"https://gmail.com"] && 131 [[toast subtitle] isEqualToString:@"https://gmail.com"] &&
132 [[toast actionButtonTitle] isEqualToString:@"Settings"] && 132 [[toast actionButtonTitle] isEqualToString:@"Settings"] &&
133 [[toast otherButtonTitle] isEqualToString:@"Close"]; 133 [[toast otherButtonTitle] isEqualToString:@"Close"];
134 }]]; 134 }]];
135 bridge->Display(NotificationCommon::PERSISTENT, 135 bridge->Display(NotificationCommon::PERSISTENT, "notification_id",
136 "notification_id", "profile_id", false, *notification); 136 "profile_id", false, *notification);
137 [notificationCenter verify]; 137 [notificationCenter verify];
138 } 138 }
139 139
140 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayOneButton) { 140 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayOneButton) {
141 std::unique_ptr<Notification> notification = 141 std::unique_ptr<Notification> notification =
142 NotificationGenerator::CreateNotification( 142 NotificationGenerator::CreateNotification(
143 "Title", "Context", "https://gmail.com", "Button 1", "", 143 "Title", "Context", "https://gmail.com", "Button 1", "",
144 message_center::NOTIFICATION_TYPE_SIMPLE); 144 message_center::NOTIFICATION_TYPE_SIMPLE);
145 145
146 id notificationCenter = 146 id notificationCenter =
147 [OCMockObject mockForClass:[NSUserNotificationCenter class]]; 147 [OCMockObject mockForClass:[NSUserNotificationCenter class]];
148 NotificationPlatformBridgeMac* bridge = new NotificationPlatformBridgeMac( 148 NotificationPlatformBridgeMac* bridge = new NotificationPlatformBridgeMac(
149 notificationCenter, false /* set_delegate */); 149 notificationCenter, false /* set_delegate */);
150 [[notificationCenter expect] 150 [[notificationCenter expect]
151 deliverNotification:[OCMArg checkWithBlock:^BOOL(id toast) { 151 deliverNotification:[OCMArg checkWithBlock:^BOOL(id toast) {
152 return [[toast title] isEqualToString:@"Title"] && 152 return [[toast title] isEqualToString:@"Title"] &&
153 [[toast informativeText] isEqualToString:@"Context"] && 153 [[toast informativeText] isEqualToString:@"Context"] &&
154 [[toast subtitle] isEqualToString:@"https://gmail.com"] && 154 [[toast subtitle] isEqualToString:@"https://gmail.com"] &&
155 [[toast actionButtonTitle] isEqualToString:@"Options"] && 155 [[toast actionButtonTitle] isEqualToString:@"Options"] &&
156 [[toast otherButtonTitle] isEqualToString:@"Close"]; 156 [[toast otherButtonTitle] isEqualToString:@"Close"];
157 }]]; 157 }]];
158 bridge->Display(NotificationCommon::PERSISTENT, 158 bridge->Display(NotificationCommon::PERSISTENT, "notification_id",
159 "notification_id", "profile_id", false, *notification); 159 "profile_id", false, *notification);
160 [notificationCenter verify]; 160 [notificationCenter verify];
161 } 161 }
162
163 // FAILURE: Uses a nice mock instead of a mock which *should* not
164 // not care about uncalled methods.
165 // Crashes with : *** -[NSProxy doesNotRecognizeSelector:setDelegate:] called!
166 TEST_F(NotificationPlatformBridgeMacTest, TestDisplayNiceMock) {
167 std::unique_ptr<Notification> notification =
168 NotificationGenerator::CreateNotification(
169 "Title", "Context", "https://gmail.com", "Button 1", "",
170 message_center::NOTIFICATION_TYPE_SIMPLE);
171
172 id notificationCenter =
173 [OCMockObject niceMockForClass:[NSUserNotificationCenter class]];
174 NotificationPlatformBridgeMac* bridge =
175 new NotificationPlatformBridgeMac(notificationCenter);
176 [[notificationCenter expect]
177 deliverNotification:[OCMArg checkWithBlock:^BOOL(id toast) {
178 return [[toast title] isEqualToString:@"Title"] &&
179 [[toast informativeText] isEqualToString:@"Context"] &&
180 [[toast subtitle] isEqualToString:@"https://gmail.com"] &&
181 [[toast actionButtonTitle] isEqualToString:@"Options"] &&
182 [[toast otherButtonTitle] isEqualToString:@"Close"];
183 }]];
184 bridge->Display(NotificationCommon::PERSISTENT, "notification_id",
185 "profile_id", false, *notification);
186 [notificationCenter verify];
187 }
188
189 // Close: Set the property as if it was a method.
190 // Fails with
191 // [NSProxy doesNotRecognizeSelector:deliveredNotifications] called!
192 TEST_F(NotificationPlatformBridgeMacTest, TestCloseOneWay) {
193 id notificationCenter =
194 [OCMockObject niceMockForClass:[NSUserNotificationCenter class]];
195 NotificationPlatformBridgeMac* bridge =
196 new NotificationPlatformBridgeMac(notificationCenter, false);
197 [[notificationCenter expect] deliveredNotifications];
198 bridge->Close("profile_id", "notification_id");
199 [notificationCenter verify];
200 }
201
202 // Close: Set the property as a key value pair in the documentation.
203 // Fails with
204 // [NSProxy doesNotRecognizeSelector:deliveredNotifications] called!
205 TEST_F(NotificationPlatformBridgeMacTest, TestCloseAnotherWay) {
206 id notificationCenter =
207 [OCMockObject niceMockForClass:[NSUserNotificationCenter class]];
208 NotificationPlatformBridgeMac* bridge =
209 new NotificationPlatformBridgeMac(notificationCenter, false);
210 [[(id)notificationCenter expect] deliveredNotifications];
211 bridge->Close("profile_id", "notification_id");
212 [notificationCenter verify];
213 }
OLDNEW
« no previous file with comments | « chrome/browser/notifications/notification_platform_bridge_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698