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

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

Issue 2458703003: Create a stub NSUserNotificationCenter and make tests use it. (Closed)
Patch Set: review Created 4 years, 1 month 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/stub_notification_center_mac.h ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "chrome/browser/notifications/stub_notification_center_mac.h"
Robert Sesek 2016/11/07 16:16:50 #import instead of #include here
Miguel Garcia 2016/11/07 18:22:25 Done, it is not really clear to me what are the ru
6
7 #include "base/logging.h"
8 #include "base/mac/scoped_nsobject.h"
9 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h"
10
11 @implementation StubNotificationCenter {
12 base::scoped_nsobject<NSMutableArray> alerts_;
13 }
14
15 - (instancetype)init {
16 if ((self = [super init])) {
17 alerts_.reset([[NSMutableArray alloc] init]);
18 }
19 return self;
20 }
21
22 // The default implementation adds some extra checks on what constructors can
23 // be used. isKindOfClass bypasses all of that.
24 - (BOOL)isKindOfClass:(Class)cls {
25 if ([cls isEqual:NSClassFromString(@"_NSConcreteUserNotificationCenter")]) {
26 return YES;
27 }
28 return [super isKindOfClass:cls];
29 }
30
31 - (void)deliverNotification:(NSUserNotification*)notification {
32 [alerts_ addObject:notification];
33 }
34
35 - (NSArray*)deliveredNotifications {
36 return [[alerts_ copy] autorelease];
37 }
38
39 - (void)removeDeliveredNotification:(NSUserNotification*)notification {
40 NSString* notificationId = [notification.userInfo
41 objectForKey:notification_constants::kNotificationId];
42 NSString* profileId = [notification.userInfo
43 objectForKey:notification_constants::kNotificationProfileId];
44 DCHECK(profileId);
45 DCHECK(notificationId);
46 for (NSUserNotification* toast in alerts_.get()) {
47 NSString* toastId =
48 [toast.userInfo objectForKey:notification_constants::kNotificationId];
49 NSString* persistentProfileId = [toast.userInfo
50 objectForKey:notification_constants::kNotificationProfileId];
51 if ([toastId isEqualToString:notificationId] &&
52 [persistentProfileId isEqualToString:profileId]) {
53 [alerts_ removeObject:toast];
54 break;
55 }
56 }
57 }
58
59 - (void)removeAllDeliveredNotifications {
60 [alerts_ removeAllObjects];
61 }
62
63 // Need to provide a nop implementation of setDelegate as it is
64 // used during the setup of the bridge.
65 - (void)setDelegate:(NSUserNotificationCenterDelegate*)delegate {
66 }
67
68 @end
OLDNEW
« no previous file with comments | « chrome/browser/notifications/stub_notification_center_mac.h ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698