Index: chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm |
diff --git a/chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm b/chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ffb71a2782cb3c2150698d496b797313d8d61769 |
--- /dev/null |
+++ b/chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm |
@@ -0,0 +1,72 @@ |
+// 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 <AppKit/AppKit.h> |
+ |
+#include "base/mac/scoped_nsobject.h" |
+#include "chrome/browser/notifications/notification_platform_bridge_mac.h" |
+#include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" |
+#include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" |
+#include "chrome/browser/ui/cocoa/notifications/notification_response_builder_mac.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace { |
+NSMutableDictionary* BuildDefaultNotificationResponse() { |
+ base::scoped_nsobject<NotificationBuilder> builder( |
+ [[NotificationBuilder alloc] init]); |
+ [builder setTitle:@"Title"]; |
+ [builder setSubTitle:@"https://www.miguel.com"]; |
+ [builder setContextMessage:@""]; |
+ [builder setButtons:@"Button1" secondaryButton:@"Button2"]; |
+ [builder setTag:@"tag1"]; |
+ [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
+ [builder setNotificationId:@"notificationId"]; |
+ [builder setProfileId:@"profileId"]; |
+ [builder setIncognito:false]; |
+ [builder setNotificationType:[NSNumber numberWithInt:0]]; |
+ |
+ NSUserNotification* notification = [builder buildUserNotification]; |
+ return [NSMutableDictionary |
+ dictionaryWithDictionary:[NotificationResponseBuilder |
+ buildDictionary:notification]]; |
+} |
+} // namespace |
+ |
+TEST(NotificationPlatformBridgeMacTest, TestNotificationValidResponse) { |
+ NSDictionary* response = BuildDefaultNotificationResponse(); |
+ EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
+} |
+ |
+TEST(NotificationPlatformBridgeMacTest, TestNotificationUnknownType) { |
+ NSMutableDictionary* response = BuildDefaultNotificationResponse(); |
+ [response setValue:[NSNumber numberWithInt:210581] |
+ forKey:notification_constants::kNotificationType]; |
+ EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
+} |
+ |
+TEST(NotificationPlatformBridgeMacTest, TestNotificationUnknownOperation) { |
+ NSMutableDictionary* response = BuildDefaultNotificationResponse(); |
+ [response setValue:[NSNumber numberWithInt:40782] |
+ forKey:notification_constants::kNotificationOperation]; |
+ EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
+} |
+ |
+TEST(NotificationPlatformBridgeMacTest, TestNotificationNoProfileId) { |
+ NSMutableDictionary* response = BuildDefaultNotificationResponse(); |
+ [response removeObjectForKey:notification_constants::kNotificationProfileId]; |
+ EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
+} |
+ |
+TEST(NotificationPlatformBridgeMacTest, TestNotificationNoNotificationId) { |
+ NSMutableDictionary* response = BuildDefaultNotificationResponse(); |
+ [response setValue:@"" forKey:notification_constants::kNotificationId]; |
+ EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
+} |
+ |
+TEST(NotificationPlatformBridgeMacTest, TestNotificationInvalidButton) { |
+ NSMutableDictionary* response = BuildDefaultNotificationResponse(); |
+ [response setValue:[NSNumber numberWithInt:-5] |
+ forKey:notification_constants::kNotificationButtonIndex]; |
+ EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
+} |