OLD | NEW |
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 <AppKit/AppKit.h> | 5 #import <AppKit/AppKit.h> |
6 | 6 |
7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "chrome/browser/notifications/notification_common.h" |
8 #include "chrome/browser/notifications/notification_platform_bridge_mac.h" | 9 #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_builder_mac.h" |
10 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" | 11 #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 "chrome/browser/ui/cocoa/notifications/notification_response_builder_ma
c.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 NSMutableDictionary* BuildDefaultNotificationResponse() { | 17 NSMutableDictionary* BuildDefaultNotificationResponse() { |
17 base::scoped_nsobject<NotificationBuilder> builder( | 18 base::scoped_nsobject<NotificationBuilder> builder( |
18 [[NotificationBuilder alloc] init]); | 19 [[NotificationBuilder alloc] init]); |
19 [builder setTitle:@"Title"]; | 20 [builder setTitle:@"Title"]; |
20 [builder setSubTitle:@"https://www.miguel.com"]; | 21 [builder setSubTitle:@"https://www.miguel.com"]; |
21 [builder setOrigin:@"https://www.miguel.com/"]; | 22 [builder setOrigin:@"https://www.miguel.com/"]; |
22 [builder setContextMessage:@""]; | 23 [builder setContextMessage:@""]; |
23 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; | 24 [builder setButtons:@"Button1" secondaryButton:@"Button2"]; |
24 [builder setTag:@"tag1"]; | 25 [builder setTag:@"tag1"]; |
25 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; | 26 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
26 [builder setNotificationId:@"notificationId"]; | 27 [builder setNotificationId:@"notificationId"]; |
27 [builder setProfileId:@"profileId"]; | 28 [builder setProfileId:@"profileId"]; |
28 [builder setIncognito:false]; | 29 [builder setIncognito:false]; |
| 30 [builder |
| 31 setNotificationType:[NSNumber |
| 32 numberWithInt:static_cast< |
| 33 NotificationCommon::Type>(0)]]; |
29 | 34 |
30 NSUserNotification* notification = [builder buildUserNotification]; | 35 NSUserNotification* notification = [builder buildUserNotification]; |
31 return [NSMutableDictionary | 36 return [NSMutableDictionary |
32 dictionaryWithDictionary:[NotificationResponseBuilder | 37 dictionaryWithDictionary:[NotificationResponseBuilder |
33 buildDictionary:notification]]; | 38 buildDictionary:notification]]; |
34 } | 39 } |
35 | 40 |
36 } // namespace | 41 } // namespace |
37 | 42 |
38 TEST(NotificationPlatformBridgeMacTest, TestNotificationValidResponse) { | 43 TEST(NotificationPlatformBridgeMacTest, TestNotificationValidResponse) { |
39 NSDictionary* response = BuildDefaultNotificationResponse(); | 44 NSDictionary* response = BuildDefaultNotificationResponse(); |
40 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); | 45 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
41 } | 46 } |
42 | 47 |
| 48 TEST(NotificationPlatformBridgeMacTest, TestNotificationUnknownType) { |
| 49 NSMutableDictionary* response = BuildDefaultNotificationResponse(); |
| 50 [response setValue:[NSNumber numberWithInt:210581] |
| 51 forKey:notification_constants::kNotificationType]; |
| 52 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
| 53 } |
| 54 |
43 TEST(NotificationPlatformBridgeMacTest, TestNotificationUnknownOperation) { | 55 TEST(NotificationPlatformBridgeMacTest, TestNotificationUnknownOperation) { |
44 NSMutableDictionary* response = BuildDefaultNotificationResponse(); | 56 NSMutableDictionary* response = BuildDefaultNotificationResponse(); |
45 [response setValue:[NSNumber numberWithInt:40782] | 57 [response setValue:[NSNumber numberWithInt:40782] |
46 forKey:notification_constants::kNotificationOperation]; | 58 forKey:notification_constants::kNotificationOperation]; |
47 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); | 59 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
48 } | 60 } |
49 | 61 |
50 TEST(NotificationPlatformBridgeMacTest, TestNotificationMissingOperation) { | 62 TEST(NotificationPlatformBridgeMacTest, TestNotificationMissingOperation) { |
51 NSMutableDictionary* response = BuildDefaultNotificationResponse(); | 63 NSMutableDictionary* response = BuildDefaultNotificationResponse(); |
52 [response removeObjectForKey:notification_constants::kNotificationOperation]; | 64 [response removeObjectForKey:notification_constants::kNotificationOperation]; |
(...skipping 29 matching lines...) Expand all Loading... |
82 TEST(NotificationPlatformBridgeMacTest, TestNotificationOrigin) { | 94 TEST(NotificationPlatformBridgeMacTest, TestNotificationOrigin) { |
83 NSMutableDictionary* response = BuildDefaultNotificationResponse(); | 95 NSMutableDictionary* response = BuildDefaultNotificationResponse(); |
84 [response setValue:@"invalidorigin" | 96 [response setValue:@"invalidorigin" |
85 forKey:notification_constants::kNotificationOrigin]; | 97 forKey:notification_constants::kNotificationOrigin]; |
86 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); | 98 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
87 | 99 |
88 // If however the origin is not present the response should be fine. | 100 // If however the origin is not present the response should be fine. |
89 [response removeObjectForKey:notification_constants::kNotificationOrigin]; | 101 [response removeObjectForKey:notification_constants::kNotificationOrigin]; |
90 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); | 102 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); |
91 } | 103 } |
OLD | NEW |