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

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

Issue 2105863002: Verify that the notification response contains sensible data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
(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
16 NSMutableDictionary* BuildDefaultNotificationResponse() {
17 base::scoped_nsobject<NotificationBuilder> builder(
18 [[NotificationBuilder alloc] init]);
19 [builder setTitle:@"Title"];
20 [builder setSubTitle:@"https://www.miguel.com"];
21 [builder setOrigin:@"https://www.miguel.com/"];
22 [builder setContextMessage:@""];
23 [builder setButtons:@"Button1" secondaryButton:@"Button2"];
24 [builder setTag:@"tag1"];
25 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]];
26 [builder setNotificationId:@"notificationId"];
27 [builder setProfileId:@"profileId"];
28 [builder setIncognito:false];
29
30 NSUserNotification* notification = [builder buildUserNotification];
31 return [NSMutableDictionary
32 dictionaryWithDictionary:[NotificationResponseBuilder
33 buildDictionary:notification]];
34 }
35
36 } // namespace
37
38 TEST(NotificationPlatformBridgeMacTest, TestNotificationValidResponse) {
39 NSDictionary* response = BuildDefaultNotificationResponse();
40 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response));
41 }
42
43 TEST(NotificationPlatformBridgeMacTest, TestNotificationUnknownOperation) {
44 NSMutableDictionary* response = BuildDefaultNotificationResponse();
45 [response setValue:[NSNumber numberWithInt:40782]
46 forKey:notification_constants::kNotificationOperation];
47 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response));
48 }
49
50 TEST(NotificationPlatformBridgeMacTest, TestNotificationMissingOperation) {
51 NSMutableDictionary* response = BuildDefaultNotificationResponse();
52 [response removeObjectForKey:notification_constants::kNotificationOperation];
53 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response));
54 }
55
56 TEST(NotificationPlatformBridgeMacTest, TestNotificationNoProfileId) {
57 NSMutableDictionary* response = BuildDefaultNotificationResponse();
58 [response removeObjectForKey:notification_constants::kNotificationProfileId];
59 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response));
60 }
61
62 TEST(NotificationPlatformBridgeMacTest, TestNotificationNoNotificationId) {
63 NSMutableDictionary* response = BuildDefaultNotificationResponse();
64 [response setValue:@"" forKey:notification_constants::kNotificationId];
65 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response));
66 }
67
68 TEST(NotificationPlatformBridgeMacTest, TestNotificationInvalidButton) {
69 NSMutableDictionary* response = BuildDefaultNotificationResponse();
70 [response setValue:[NSNumber numberWithInt:-5]
71 forKey:notification_constants::kNotificationButtonIndex];
72 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response));
73 }
74
75 TEST(NotificationPlatformBridgeMacTest, TestNotificationMissingButtonIndex) {
76 NSMutableDictionary* response = BuildDefaultNotificationResponse();
77 [response
78 removeObjectForKey:notification_constants::kNotificationButtonIndex];
79 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response));
80 }
81
82 TEST(NotificationPlatformBridgeMacTest, TestNotificationOrigin) {
83 NSMutableDictionary* response = BuildDefaultNotificationResponse();
84 [response setValue:@"invalidorigin"
85 forKey:notification_constants::kNotificationOrigin];
86 EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response));
87
88 // If however the origin is not present the response should be fine.
89 [response removeObjectForKey:notification_constants::kNotificationOrigin];
90 EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response));
91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698