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

Unified Diff: chrome/browser/notifications/stub_alert_dispatcher_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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/stub_alert_dispatcher_mac.mm
diff --git a/chrome/browser/notifications/stub_alert_dispatcher_mac.mm b/chrome/browser/notifications/stub_alert_dispatcher_mac.mm
new file mode 100644
index 0000000000000000000000000000000000000000..2c193f78eaaf0d206a52922bb41825e410d4eb97
--- /dev/null
+++ b/chrome/browser/notifications/stub_alert_dispatcher_mac.mm
@@ -0,0 +1,50 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/notifications/stub_alert_dispatcher_mac.h"
+
+#include "base/mac/scoped_nsobject.h"
+#include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h"
+
+@implementation StubAlertDispatcher {
+ base::scoped_nsobject<NSMutableArray> alerts_;
+}
+
+- (instancetype)init {
+ if ((self = [super init])) {
+ alerts_.reset([[NSMutableArray alloc] init]);
+ }
+ return self;
+}
+
+- (void)dispatchNotification:(NSDictionary*)data {
+ [alerts_ addObject:data];
+}
+
+- (void)closeNotificationWithId:(NSString*)notificationId
+ withProfileId:(NSString*)profileId {
+ DCHECK(profileId);
+ DCHECK(notificationId);
+ for (NSDictionary* toast in alerts_.get()) {
+ NSString* toastId =
+ [toast objectForKey:notification_constants::kNotificationId];
+ NSString* persistentProfileId =
+ [toast objectForKey:notification_constants::kNotificationProfileId];
+ if ([toastId isEqualToString:notificationId] &&
+ [persistentProfileId isEqualToString:profileId]) {
+ [alerts_ removeObject:toast];
+ break;
+ }
+ }
+}
+
+- (void)closeAllNotifications {
+ [alerts_ removeAllObjects];
+}
+
+- (NSArray*)alerts {
+ return [[alerts_ copy] autorelease];
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698