Chromium Code Reviews| 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 | |
| 28 NSUserNotification* notification = [builder buildUserNotification]; | |
| 29 return [NSMutableDictionary | |
| 30 dictionaryWithDictionary:[NotificationResponseBuilder | |
| 31 buildDictionary:notification]]; | |
| 32 } | |
| 33 } // 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.
| |
| 34 | |
| 35 TEST(NotificationPlatformBridgeMacTest, TestNotificationValidResponse) { | |
| 36 NSDictionary* response = BuildDefaultNotificationResponse(); | |
| 37 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); | |
| 38 } | |
| 39 | |
| 40 TEST(NotificationPlatformBridgeMacTest, TestNotificationUnknownOperation) { | |
| 41 NSMutableDictionary* response = BuildDefaultNotificationResponse(); | |
| 42 [response setValue:[NSNumber numberWithInt:40782] | |
| 43 forKey:notification_constants::kNotificationOperation]; | |
| 44 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); | |
| 45 } | |
| 46 | |
| 47 TEST(NotificationPlatformBridgeMacTest, TestNotificationNoProfileId) { | |
| 48 NSMutableDictionary* response = BuildDefaultNotificationResponse(); | |
| 49 [response removeObjectForKey:notification_constants::kNotificationProfileId]; | |
| 50 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); | |
| 51 } | |
| 52 | |
| 53 TEST(NotificationPlatformBridgeMacTest, TestNotificationNoNotificationId) { | |
| 54 NSMutableDictionary* response = BuildDefaultNotificationResponse(); | |
| 55 [response setValue:@"" forKey:notification_constants::kNotificationId]; | |
| 56 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); | |
| 57 } | |
| 58 | |
| 59 TEST(NotificationPlatformBridgeMacTest, TestNotificationInvalidButton) { | |
| 60 NSMutableDictionary* response = BuildDefaultNotificationResponse(); | |
| 61 [response setValue:[NSNumber numberWithInt:-5] | |
| 62 forKey:notification_constants::kNotificationButtonIndex]; | |
| 63 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); | |
| 64 } | |
|
Peter Beverloo
2016/06/28 23:35:52
Add tests for missing `operation` and `buttonIndex
Miguel Garcia
2016/06/30 10:42:00
Done.
| |
| OLD | NEW |