| OLD | NEW |
| 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 "config.h" | 5 #include "config.h" |
| 6 #include "modules/notifications/NotificationData.h" | 6 #include "modules/notifications/NotificationData.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/modules/v8/UnionTypesModules.h" | 9 #include "bindings/modules/v8/UnionTypesModules.h" |
| 10 #include "core/testing/NullExecutionContext.h" | 10 #include "core/testing/NullExecutionContext.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 options.setDir(direction); | 172 options.setDir(direction); |
| 173 | 173 |
| 174 TrackExceptionState exceptionState; | 174 TrackExceptionState exceptionState; |
| 175 WebNotificationData notificationData = createWebNotificationData(executi
onContext(), kNotificationTitle, options, exceptionState); | 175 WebNotificationData notificationData = createWebNotificationData(executi
onContext(), kNotificationTitle, options, exceptionState); |
| 176 ASSERT_FALSE(exceptionState.hadException()); | 176 ASSERT_FALSE(exceptionState.hadException()); |
| 177 | 177 |
| 178 EXPECT_EQ(mappings.get(direction), notificationData.direction); | 178 EXPECT_EQ(mappings.get(direction), notificationData.direction); |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| 182 TEST_F(NotificationDataTest, RequiredActionProperties) | |
| 183 { | |
| 184 NotificationOptions options; | |
| 185 | |
| 186 // The NotificationAction.action property is required. | |
| 187 { | |
| 188 NotificationAction action; | |
| 189 action.setTitle(kNotificationActionTitle); | |
| 190 | |
| 191 HeapVector<NotificationAction> actions; | |
| 192 actions.append(action); | |
| 193 | |
| 194 options.setActions(actions); | |
| 195 | |
| 196 TrackExceptionState exceptionState; | |
| 197 WebNotificationData notificationData = createWebNotificationData(executi
onContext(), kNotificationTitle, options, exceptionState); | |
| 198 ASSERT_TRUE(exceptionState.hadException()); | |
| 199 EXPECT_EQ("NotificationAction `action` must not be empty.", exceptionSta
te.message()); | |
| 200 } | |
| 201 | |
| 202 // The NotificationAction.title property is required. | |
| 203 { | |
| 204 NotificationAction action; | |
| 205 action.setAction(kNotificationActionAction); | |
| 206 | |
| 207 HeapVector<NotificationAction> actions; | |
| 208 actions.append(action); | |
| 209 | |
| 210 options.setActions(actions); | |
| 211 | |
| 212 TrackExceptionState exceptionState; | |
| 213 WebNotificationData notificationData = createWebNotificationData(executi
onContext(), kNotificationTitle, options, exceptionState); | |
| 214 ASSERT_TRUE(exceptionState.hadException()); | |
| 215 EXPECT_EQ("NotificationAction `title` must not be empty.", exceptionStat
e.message()); | |
| 216 } | |
| 217 } | |
| 218 | |
| 219 TEST_F(NotificationDataTest, MaximumActionCount) | 182 TEST_F(NotificationDataTest, MaximumActionCount) |
| 220 { | 183 { |
| 221 HeapVector<NotificationAction> actions; | 184 HeapVector<NotificationAction> actions; |
| 222 for (size_t i = 0; i < Notification::maxActions() + 2; ++i) { | 185 for (size_t i = 0; i < Notification::maxActions() + 2; ++i) { |
| 223 NotificationAction action; | 186 NotificationAction action; |
| 224 action.setAction(String::number(i)); | 187 action.setAction(String::number(i)); |
| 225 action.setTitle(kNotificationActionTitle); | 188 action.setTitle(kNotificationActionTitle); |
| 226 | 189 |
| 227 actions.append(action); | 190 actions.append(action); |
| 228 } | 191 } |
| 229 | 192 |
| 230 NotificationOptions options; | 193 NotificationOptions options; |
| 231 options.setActions(actions); | 194 options.setActions(actions); |
| 232 | 195 |
| 233 TrackExceptionState exceptionState; | 196 TrackExceptionState exceptionState; |
| 234 WebNotificationData notificationData = createWebNotificationData(executionCo
ntext(), kNotificationTitle, options, exceptionState); | 197 WebNotificationData notificationData = createWebNotificationData(executionCo
ntext(), kNotificationTitle, options, exceptionState); |
| 235 ASSERT_FALSE(exceptionState.hadException()); | 198 ASSERT_FALSE(exceptionState.hadException()); |
| 236 | 199 |
| 237 // The stored actions will be capped to |maxActions| entries. | 200 // The stored actions will be capped to |maxActions| entries. |
| 238 ASSERT_EQ(Notification::maxActions(), notificationData.actions.size()); | 201 ASSERT_EQ(Notification::maxActions(), notificationData.actions.size()); |
| 239 | 202 |
| 240 for (size_t i = 0; i < Notification::maxActions(); ++i) { | 203 for (size_t i = 0; i < Notification::maxActions(); ++i) { |
| 241 WebString expectedAction = String::number(i); | 204 WebString expectedAction = String::number(i); |
| 242 EXPECT_EQ(expectedAction, notificationData.actions[i].action); | 205 EXPECT_EQ(expectedAction, notificationData.actions[i].action); |
| 243 } | 206 } |
| 244 } | 207 } |
| 245 | 208 |
| 246 } // namespace | 209 } // namespace |
| 247 } // namespace blink | 210 } // namespace blink |
| OLD | NEW |