OLD | NEW |
(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 #import <AppKit/AppKit.h> |
| 6 |
| 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "chrome/browser/notifications/notification_platform_bridge_mac.h" |
| 9 #include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" |
| 10 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" |
| 11 #include "chrome/browser/ui/cocoa/notifications/notification_response_builder_ma
c.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace { |
| 15 NSMutableDictionary* BuildDefaultNotificationResponse() { |
| 16 base::scoped_nsobject<NotificationBuilder> builder( |
| 17 [[NotificationBuilder alloc] init]); |
| 18 [builder setTitle:@"Title"]; |
| 19 [builder setSubTitle:@"https://www.miguel.com"]; |
| 20 [builder setContextMessage:@""]; |
| 21 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; |
| 22 [builder setTag:@"tag1"]; |
| 23 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
| 24 [builder setNotificationId:@"notificationId"]; |
| 25 [builder setProfileId:@"profileId"]; |
| 26 [builder setIncognito:false]; |
| 27 [builder setNotificationType:[NSNumber numberWithInt:0]]; |
| 28 |
| 29 NSUserNotification* notification = [builder buildUserNotification]; |
| 30 return [NSMutableDictionary |
| 31 dictionaryWithDictionary:[NotificationResponseBuilder |
| 32 buildDictionary:notification]]; |
| 33 } |
| 34 } // namespace |
| 35 |
| 36 TEST(NotificationPlatformBridgeMacTest, TestNotificationValidResponse) { |
| 37 NSDictionary* response = BuildDefaultNotificationResponse(); |
| 38 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
| 39 } |
| 40 |
| 41 TEST(NotificationPlatformBridgeMacTest, TestNotificationUnknownType) { |
| 42 NSMutableDictionary* response = BuildDefaultNotificationResponse(); |
| 43 [response setValue:[NSNumber numberWithInt:210581] |
| 44 forKey:notification_constants::kNotificationType]; |
| 45 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
| 46 } |
| 47 |
| 48 TEST(NotificationPlatformBridgeMacTest, TestNotificationUnknownOperation) { |
| 49 NSMutableDictionary* response = BuildDefaultNotificationResponse(); |
| 50 [response setValue:[NSNumber numberWithInt:40782] |
| 51 forKey:notification_constants::kNotificationOperation]; |
| 52 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
| 53 } |
| 54 |
| 55 TEST(NotificationPlatformBridgeMacTest, TestNotificationNoProfileId) { |
| 56 NSMutableDictionary* response = BuildDefaultNotificationResponse(); |
| 57 [response removeObjectForKey:notification_constants::kNotificationProfileId]; |
| 58 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
| 59 } |
| 60 |
| 61 TEST(NotificationPlatformBridgeMacTest, TestNotificationNoNotificationId) { |
| 62 NSMutableDictionary* response = BuildDefaultNotificationResponse(); |
| 63 [response setValue:@"" forKey:notification_constants::kNotificationId]; |
| 64 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
| 65 } |
| 66 |
| 67 TEST(NotificationPlatformBridgeMacTest, TestNotificationInvalidButton) { |
| 68 NSMutableDictionary* response = BuildDefaultNotificationResponse(); |
| 69 [response setValue:[NSNumber numberWithInt:-5] |
| 70 forKey:notification_constants::kNotificationButtonIndex]; |
| 71 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
| 72 } |
OLD | NEW |