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

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

Powered by Google App Engine
This is Rietveld 408576698