Chromium Code Reviews| 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..2740f2d3200f2725983a4c8269b2625544f43867 |
| --- /dev/null |
| +++ b/chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm |
| @@ -0,0 +1,64 @@ |
| +// 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]; |
| + |
| + NSUserNotification* notification = [builder buildUserNotification]; |
| + return [NSMutableDictionary |
| + dictionaryWithDictionary:[NotificationResponseBuilder |
| + buildDictionary:notification]]; |
| +} |
| +} // namespace |
|
Peter Beverloo
2016/06/28 23:35:52
nit: the first and final line of the anonymous nam
Miguel Garcia
2016/06/30 10:42:00
Done.
|
| + |
| +TEST(NotificationPlatformBridgeMacTest, TestNotificationValidResponse) { |
| + NSDictionary* response = BuildDefaultNotificationResponse(); |
| + EXPECT_TRUE(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)); |
| +} |
|
Peter Beverloo
2016/06/28 23:35:52
Add tests for missing `operation` and `buttonIndex
Miguel Garcia
2016/06/30 10:42:00
Done.
|