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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/notifications/notification_platform_bridge_mac.mm ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..509729a5db138ef14d2fbe42e534c1cde44bfd7f
--- /dev/null
+++ b/chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm
@@ -0,0 +1,91 @@
+// 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 setOrigin:@"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
+
+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, TestNotificationMissingOperation) {
+ NSMutableDictionary* response = BuildDefaultNotificationResponse();
+ [response removeObjectForKey: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));
+}
+
+TEST(NotificationPlatformBridgeMacTest, TestNotificationMissingButtonIndex) {
+ NSMutableDictionary* response = BuildDefaultNotificationResponse();
+ [response
+ removeObjectForKey:notification_constants::kNotificationButtonIndex];
+ EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response));
+}
+
+TEST(NotificationPlatformBridgeMacTest, TestNotificationOrigin) {
+ NSMutableDictionary* response = BuildDefaultNotificationResponse();
+ [response setValue:@"invalidorigin"
+ forKey:notification_constants::kNotificationOrigin];
+ EXPECT_FALSE(NotificationPlatformBridgeMac::VerifyNotificationData(response));
+
+ // If however the origin is not present the response should be fine.
+ [response removeObjectForKey:notification_constants::kNotificationOrigin];
+ EXPECT_TRUE(NotificationPlatformBridgeMac::VerifyNotificationData(response));
+}
« no previous file with comments | « chrome/browser/notifications/notification_platform_bridge_mac.mm ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698