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

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

Issue 2479143003: Add tests for the XPC client. (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
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 "chrome/browser/notifications/stub_notification_center_mac.h" 5 #import "chrome/browser/notifications/stub_notification_center_mac.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/mac/scoped_nsobject.h" 8 #include "base/mac/scoped_nsobject.h"
9 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" 9 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h"
10 10
11 @implementation StubNotificationCenter { 11 @implementation StubNotificationCenter {
12 base::scoped_nsobject<NSMutableArray> alerts_; 12 base::scoped_nsobject<NSMutableArray> banners_;
13 } 13 }
14 14
15 - (instancetype)init { 15 - (instancetype)init {
16 if ((self = [super init])) { 16 if ((self = [super init])) {
17 alerts_.reset([[NSMutableArray alloc] init]); 17 banners_.reset([[NSMutableArray alloc] init]);
18 } 18 }
19 return self; 19 return self;
20 } 20 }
21 21
22 // The default implementation adds some extra checks on what constructors can 22 // The default implementation adds some extra checks on what constructors can
23 // be used. isKindOfClass bypasses all of that. 23 // be used. isKindOfClass bypasses all of that.
24 - (BOOL)isKindOfClass:(Class)cls { 24 - (BOOL)isKindOfClass:(Class)cls {
25 if ([cls isEqual:NSClassFromString(@"_NSConcreteUserNotificationCenter")]) { 25 if ([cls isEqual:NSClassFromString(@"_NSConcreteUserNotificationCenter")]) {
26 return YES; 26 return YES;
27 } 27 }
28 return [super isKindOfClass:cls]; 28 return [super isKindOfClass:cls];
29 } 29 }
30 30
31 - (void)deliverNotification:(NSUserNotification*)notification { 31 - (void)deliverNotification:(NSUserNotification*)notification {
32 [alerts_ addObject:notification]; 32 [banners_ addObject:notification];
33 } 33 }
34 34
35 - (NSArray*)deliveredNotifications { 35 - (NSArray*)deliveredNotifications {
36 return [[alerts_ copy] autorelease]; 36 return [[banners_ copy] autorelease];
37 } 37 }
38 38
39 - (void)removeDeliveredNotification:(NSUserNotification*)notification { 39 - (void)removeDeliveredNotification:(NSUserNotification*)notification {
40 NSString* notificationId = [notification.userInfo 40 NSString* notificationId = [notification.userInfo
41 objectForKey:notification_constants::kNotificationId]; 41 objectForKey:notification_constants::kNotificationId];
42 NSString* profileId = [notification.userInfo 42 NSString* profileId = [notification.userInfo
43 objectForKey:notification_constants::kNotificationProfileId]; 43 objectForKey:notification_constants::kNotificationProfileId];
44 DCHECK(profileId); 44 DCHECK(profileId);
45 DCHECK(notificationId); 45 DCHECK(notificationId);
46 for (NSUserNotification* toast in alerts_.get()) { 46 for (NSUserNotification* toast in banners_.get()) {
47 NSString* toastId = 47 NSString* toastId =
48 [toast.userInfo objectForKey:notification_constants::kNotificationId]; 48 [toast.userInfo objectForKey:notification_constants::kNotificationId];
49 NSString* persistentProfileId = [toast.userInfo 49 NSString* persistentProfileId = [toast.userInfo
50 objectForKey:notification_constants::kNotificationProfileId]; 50 objectForKey:notification_constants::kNotificationProfileId];
51 if ([toastId isEqualToString:notificationId] && 51 if ([toastId isEqualToString:notificationId] &&
52 [persistentProfileId isEqualToString:profileId]) { 52 [persistentProfileId isEqualToString:profileId]) {
53 [alerts_ removeObject:toast]; 53 [banners_ removeObject:toast];
54 break; 54 break;
55 } 55 }
56 } 56 }
57 } 57 }
58 58
59 - (void)removeAllDeliveredNotifications { 59 - (void)removeAllDeliveredNotifications {
60 [alerts_ removeAllObjects]; 60 [banners_ removeAllObjects];
61 } 61 }
62 62
63 // Need to provide a nop implementation of setDelegate as it is 63 // Need to provide a nop implementation of setDelegate as it is
64 // used during the setup of the bridge. 64 // used during the setup of the bridge.
65 - (void)setDelegate:(id<NSUserNotificationCenterDelegate>)delegate { 65 - (void)setDelegate:(id<NSUserNotificationCenterDelegate>)delegate {
66 } 66 }
67 67
68 @end 68 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698