Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm

Issue 2093953002: Introduce a new API to handle native notification clicks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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:NotificationCommon::PERSISTENT]];
29 33
30 NSUserNotification* notification = [builder buildUserNotification]; 34 NSUserNotification* notification = [builder buildUserNotification];
31 return [NSMutableDictionary 35 return [NSMutableDictionary
32 dictionaryWithDictionary:[NotificationResponseBuilder 36 dictionaryWithDictionary:[NotificationResponseBuilder
33 buildDictionary:notification]]; 37 buildDictionary:notification]];
34 } 38 }
35 39
36 } // namespace 40 } // namespace
37 41
38 TEST(NotificationPlatformBridgeMacTest, TestNotificationValidResponse) { 42 TEST(NotificationPlatformBridgeMacTest, TestNotificationValidResponse) {
39 NSDictionary* response = BuildDefaultNotificationResponse(); 43 NSDictionary* response = BuildDefaultNotificationResponse();
40 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); 44 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response));
41 } 45 }
42 46
47 TEST(NotificationPlatformBridgeMacTest, TestNotificationUnknownType) {
48 NSMutableDictionary* response = BuildDefaultNotificationResponse();
49 [response setValue:[NSNumber numberWithInt:210581]
50 forKey:notification_constants::kNotificationType];
51 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response));
52 }
53
43 TEST(NotificationPlatformBridgeMacTest, TestNotificationUnknownOperation) { 54 TEST(NotificationPlatformBridgeMacTest, TestNotificationUnknownOperation) {
44 NSMutableDictionary* response = BuildDefaultNotificationResponse(); 55 NSMutableDictionary* response = BuildDefaultNotificationResponse();
45 [response setValue:[NSNumber numberWithInt:40782] 56 [response setValue:[NSNumber numberWithInt:40782]
46 forKey:notification_constants::kNotificationOperation]; 57 forKey:notification_constants::kNotificationOperation];
47 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); 58 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response));
48 } 59 }
49 60
50 TEST(NotificationPlatformBridgeMacTest, TestNotificationMissingOperation) { 61 TEST(NotificationPlatformBridgeMacTest, TestNotificationMissingOperation) {
51 NSMutableDictionary* response = BuildDefaultNotificationResponse(); 62 NSMutableDictionary* response = BuildDefaultNotificationResponse();
52 [response removeObjectForKey:notification_constants::kNotificationOperation]; 63 [response removeObjectForKey:notification_constants::kNotificationOperation];
(...skipping 29 matching lines...) Expand all
82 TEST(NotificationPlatformBridgeMacTest, TestNotificationOrigin) { 93 TEST(NotificationPlatformBridgeMacTest, TestNotificationOrigin) {
83 NSMutableDictionary* response = BuildDefaultNotificationResponse(); 94 NSMutableDictionary* response = BuildDefaultNotificationResponse();
84 [response setValue:@"invalidorigin" 95 [response setValue:@"invalidorigin"
85 forKey:notification_constants::kNotificationOrigin]; 96 forKey:notification_constants::kNotificationOrigin];
86 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); 97 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response));
87 98
88 // If however the origin is not present the response should be fine. 99 // If however the origin is not present the response should be fine.
89 [response removeObjectForKey:notification_constants::kNotificationOrigin]; 100 [response removeObjectForKey:notification_constants::kNotificationOrigin];
90 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response)); 101 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response));
91 } 102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698