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

Side by Side Diff: content/browser/notifications/notification_database_data_unittest.cc

Issue 1855443002: Implement receiving side of web notification inline replies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test and removed unnecessary code. Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/strings/nullable_string16.h"
9 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
11 #include "base/time/time.h" 12 #include "base/time/time.h"
12 #include "content/browser/notifications/notification_database_data.pb.h" 13 #include "content/browser/notifications/notification_database_data.pb.h"
13 #include "content/browser/notifications/notification_database_data_conversions.h " 14 #include "content/browser/notifications/notification_database_data_conversions.h "
14 #include "content/common/notification_constants.h" 15 #include "content/common/notification_constants.h"
15 #include "content/public/browser/notification_database_data.h" 16 #include "content/public/browser/notification_database_data.h"
16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace content { 20 namespace content {
20 21
21 const int64_t kNotificationId = 42; 22 const int64_t kNotificationId = 42;
22 const int64_t kServiceWorkerRegistrationId = 9001; 23 const int64_t kServiceWorkerRegistrationId = 9001;
23 24
25 const PlatformNotificationActionType kNotificationActionType =
26 PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT;
24 const char kOrigin[] = "https://example.com/"; 27 const char kOrigin[] = "https://example.com/";
25 const char kNotificationTitle[] = "My Notification"; 28 const char kNotificationTitle[] = "My Notification";
26 const char kNotificationLang[] = "nl"; 29 const char kNotificationLang[] = "nl";
27 const char kNotificationBody[] = "Hello, world!"; 30 const char kNotificationBody[] = "Hello, world!";
28 const char kNotificationTag[] = "my_tag"; 31 const char kNotificationTag[] = "my_tag";
29 const char kNotificationIconUrl[] = "https://example.com/icon.png"; 32 const char kNotificationIconUrl[] = "https://example.com/icon.png";
30 const char kNotificationBadgeUrl[] = "https://example.com/badge.png"; 33 const char kNotificationBadgeUrl[] = "https://example.com/badge.png";
31 const char kNotificationActionIconUrl[] = "https://example.com/action_icon.png"; 34 const char kNotificationActionIconUrl[] = "https://example.com/action_icon.png";
32 const int kNotificationVibrationPattern[] = {100, 200, 300}; 35 const int kNotificationVibrationPattern[] = {100, 200, 300};
33 const double kNotificationTimestamp = 621046800.; 36 const double kNotificationTimestamp = 621046800.;
(...skipping 17 matching lines...) Expand all
51 notification_data.icon = GURL(kNotificationIconUrl); 54 notification_data.icon = GURL(kNotificationIconUrl);
52 notification_data.badge = GURL(kNotificationBadgeUrl); 55 notification_data.badge = GURL(kNotificationBadgeUrl);
53 notification_data.vibration_pattern = vibration_pattern; 56 notification_data.vibration_pattern = vibration_pattern;
54 notification_data.timestamp = base::Time::FromJsTime(kNotificationTimestamp); 57 notification_data.timestamp = base::Time::FromJsTime(kNotificationTimestamp);
55 notification_data.renotify = true; 58 notification_data.renotify = true;
56 notification_data.silent = true; 59 notification_data.silent = true;
57 notification_data.require_interaction = true; 60 notification_data.require_interaction = true;
58 notification_data.data = developer_data; 61 notification_data.data = developer_data;
59 for (size_t i = 0; i < kPlatformNotificationMaxActions; i++) { 62 for (size_t i = 0; i < kPlatformNotificationMaxActions; i++) {
60 PlatformNotificationAction notification_action; 63 PlatformNotificationAction notification_action;
64 notification_action.type = kNotificationActionType;
61 notification_action.action = base::SizeTToString(i); 65 notification_action.action = base::SizeTToString(i);
62 notification_action.title = base::SizeTToString16(i); 66 notification_action.title = base::SizeTToString16(i);
63 notification_action.icon = GURL(kNotificationActionIconUrl); 67 notification_action.icon = GURL(kNotificationActionIconUrl);
68 notification_action.placeholder =
69 base::NullableString16(base::SizeTToString16(i), false);
64 notification_data.actions.push_back(notification_action); 70 notification_data.actions.push_back(notification_action);
65 } 71 }
66 72
67 NotificationDatabaseData database_data; 73 NotificationDatabaseData database_data;
68 database_data.notification_id = kNotificationId; 74 database_data.notification_id = kNotificationId;
69 database_data.origin = GURL(kOrigin); 75 database_data.origin = GURL(kOrigin);
70 database_data.service_worker_registration_id = kServiceWorkerRegistrationId; 76 database_data.service_worker_registration_id = kServiceWorkerRegistrationId;
71 database_data.notification_data = notification_data; 77 database_data.notification_data = notification_data;
72 78
73 std::string serialized_data; 79 std::string serialized_data;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 EXPECT_EQ(notification_data.require_interaction, 113 EXPECT_EQ(notification_data.require_interaction,
108 copied_notification_data.require_interaction); 114 copied_notification_data.require_interaction);
109 115
110 ASSERT_EQ(developer_data.size(), copied_notification_data.data.size()); 116 ASSERT_EQ(developer_data.size(), copied_notification_data.data.size());
111 for (size_t i = 0; i < developer_data.size(); ++i) 117 for (size_t i = 0; i < developer_data.size(); ++i)
112 EXPECT_EQ(developer_data[i], copied_notification_data.data[i]); 118 EXPECT_EQ(developer_data[i], copied_notification_data.data[i]);
113 119
114 ASSERT_EQ(notification_data.actions.size(), 120 ASSERT_EQ(notification_data.actions.size(),
115 copied_notification_data.actions.size()); 121 copied_notification_data.actions.size());
116 for (size_t i = 0; i < notification_data.actions.size(); ++i) { 122 for (size_t i = 0; i < notification_data.actions.size(); ++i) {
123 EXPECT_EQ(notification_data.actions[i].type,
124 copied_notification_data.actions[i].type);
117 EXPECT_EQ(notification_data.actions[i].action, 125 EXPECT_EQ(notification_data.actions[i].action,
118 copied_notification_data.actions[i].action); 126 copied_notification_data.actions[i].action);
119 EXPECT_EQ(notification_data.actions[i].title, 127 EXPECT_EQ(notification_data.actions[i].title,
120 copied_notification_data.actions[i].title); 128 copied_notification_data.actions[i].title);
121 EXPECT_EQ(notification_data.actions[i].icon, 129 EXPECT_EQ(notification_data.actions[i].icon,
122 copied_notification_data.actions[i].icon); 130 copied_notification_data.actions[i].icon);
131 EXPECT_EQ(notification_data.actions[i].placeholder,
132 copied_notification_data.actions[i].placeholder);
133 EXPECT_FALSE(copied_notification_data.actions[i].placeholder.is_null());
123 } 134 }
124 } 135 }
125 136
137 TEST(NotificationDatabaseDataTest, SerializeAndDeserializeActionTypes) {
138 PlatformNotificationActionType action_types[] = {
139 PLATFORM_NOTIFICATION_ACTION_TYPE_BUTTON,
140 PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT};
141
142 for (PlatformNotificationActionType action_type : action_types) {
143 PlatformNotificationData notification_data;
144
145 PlatformNotificationAction action;
146 action.type = action_type;
147 notification_data.actions.push_back(action);
148
149 NotificationDatabaseData database_data;
150 database_data.notification_data = notification_data;
151
152 std::string serialized_data;
153 ASSERT_TRUE(
154 SerializeNotificationDatabaseData(database_data, &serialized_data));
155
156 NotificationDatabaseData copied_data;
157 ASSERT_TRUE(
158 DeserializeNotificationDatabaseData(serialized_data, &copied_data));
159
160 EXPECT_EQ(action_type, copied_data.notification_data.actions[0].type);
161 }
162 }
163
126 TEST(NotificationDatabaseDataTest, SerializeAndDeserializeDirections) { 164 TEST(NotificationDatabaseDataTest, SerializeAndDeserializeDirections) {
127 PlatformNotificationData::Direction directions[] = { 165 PlatformNotificationData::Direction directions[] = {
128 PlatformNotificationData::DIRECTION_LEFT_TO_RIGHT, 166 PlatformNotificationData::DIRECTION_LEFT_TO_RIGHT,
129 PlatformNotificationData::DIRECTION_RIGHT_TO_LEFT, 167 PlatformNotificationData::DIRECTION_RIGHT_TO_LEFT,
130 PlatformNotificationData::DIRECTION_AUTO}; 168 PlatformNotificationData::DIRECTION_AUTO};
131 169
132 for (size_t i = 0; i < arraysize(directions); ++i) { 170 for (size_t i = 0; i < arraysize(directions); ++i) {
133 PlatformNotificationData notification_data; 171 PlatformNotificationData notification_data;
134 notification_data.direction = directions[i]; 172 notification_data.direction = directions[i];
135 173
136 NotificationDatabaseData database_data; 174 NotificationDatabaseData database_data;
137 database_data.notification_data = notification_data; 175 database_data.notification_data = notification_data;
138 176
139 std::string serialized_data; 177 std::string serialized_data;
140 ASSERT_TRUE( 178 ASSERT_TRUE(
141 SerializeNotificationDatabaseData(database_data, &serialized_data)); 179 SerializeNotificationDatabaseData(database_data, &serialized_data));
142 180
143 NotificationDatabaseData copied_data; 181 NotificationDatabaseData copied_data;
144 ASSERT_TRUE( 182 ASSERT_TRUE(
145 DeserializeNotificationDatabaseData(serialized_data, &copied_data)); 183 DeserializeNotificationDatabaseData(serialized_data, &copied_data));
146 184
147 EXPECT_EQ(directions[i], copied_data.notification_data.direction); 185 EXPECT_EQ(directions[i], copied_data.notification_data.direction);
148 } 186 }
149 } 187 }
150 188
189 TEST(NotificationDatabaseDataTest, SerializeAndDeserializeNullPlaceholder) {
190 PlatformNotificationAction action;
191 action.type = kNotificationActionType;
192 action.placeholder = base::NullableString16(); // null string.
193
194 PlatformNotificationData notification_data;
195 notification_data.actions.push_back(action);
196
197 NotificationDatabaseData database_data;
198 database_data.notification_data = notification_data;
199
200 std::string serialized_data;
201 ASSERT_TRUE(
202 SerializeNotificationDatabaseData(database_data, &serialized_data));
203
204 NotificationDatabaseData copied_data;
205 ASSERT_TRUE(
206 DeserializeNotificationDatabaseData(serialized_data, &copied_data));
207
208 EXPECT_TRUE(copied_data.notification_data.actions[0].placeholder.is_null());
209 }
210
151 } // namespace content 211 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698