| 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 "modules/notifications/NotificationData.h" | 5 #include "modules/notifications/NotificationData.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "core/testing/NullExecutionContext.h" | 8 #include "core/testing/NullExecutionContext.h" |
| 9 #include "modules/notifications/Notification.h" | 9 #include "modules/notifications/Notification.h" |
| 10 #include "modules/notifications/NotificationOptions.h" | 10 #include "modules/notifications/NotificationOptions.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 ExecutionContext* getExecutionContext() { return m_executionContext.get(); } | 51 ExecutionContext* getExecutionContext() { return m_executionContext.get(); } |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 Persistent<ExecutionContext> m_executionContext; | 54 Persistent<ExecutionContext> m_executionContext; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 TEST_F(NotificationDataTest, ReflectProperties) { | 57 TEST_F(NotificationDataTest, ReflectProperties) { |
| 58 Vector<unsigned> vibrationPattern; | 58 Vector<unsigned> vibrationPattern; |
| 59 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNotificationVibration); ++i) | 59 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNotificationVibration); ++i) |
| 60 vibrationPattern.append(kNotificationVibration[i]); | 60 vibrationPattern.push_back(kNotificationVibration[i]); |
| 61 | 61 |
| 62 UnsignedLongOrUnsignedLongSequence vibrationSequence; | 62 UnsignedLongOrUnsignedLongSequence vibrationSequence; |
| 63 vibrationSequence.setUnsignedLongSequence(vibrationPattern); | 63 vibrationSequence.setUnsignedLongSequence(vibrationPattern); |
| 64 | 64 |
| 65 HeapVector<NotificationAction> actions; | 65 HeapVector<NotificationAction> actions; |
| 66 for (size_t i = 0; i < Notification::maxActions(); ++i) { | 66 for (size_t i = 0; i < Notification::maxActions(); ++i) { |
| 67 NotificationAction action; | 67 NotificationAction action; |
| 68 action.setType(kNotificationActionType); | 68 action.setType(kNotificationActionType); |
| 69 action.setAction(kNotificationActionAction); | 69 action.setAction(kNotificationActionAction); |
| 70 action.setTitle(kNotificationActionTitle); | 70 action.setTitle(kNotificationActionTitle); |
| 71 action.setIcon(kNotificationActionIcon); | 71 action.setIcon(kNotificationActionIcon); |
| 72 action.setPlaceholder(kNotificationActionPlaceholder); | 72 action.setPlaceholder(kNotificationActionPlaceholder); |
| 73 | 73 |
| 74 actions.append(action); | 74 actions.push_back(action); |
| 75 } | 75 } |
| 76 | 76 |
| 77 NotificationOptions options; | 77 NotificationOptions options; |
| 78 options.setDir(kNotificationDir); | 78 options.setDir(kNotificationDir); |
| 79 options.setLang(kNotificationLang); | 79 options.setLang(kNotificationLang); |
| 80 options.setBody(kNotificationBody); | 80 options.setBody(kNotificationBody); |
| 81 options.setTag(kNotificationTag); | 81 options.setTag(kNotificationTag); |
| 82 options.setImage(kNotificationImage); | 82 options.setImage(kNotificationImage); |
| 83 options.setIcon(kNotificationIcon); | 83 options.setIcon(kNotificationIcon); |
| 84 options.setBadge(kNotificationBadge); | 84 options.setBadge(kNotificationBadge); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 EXPECT_EQ(kWebNotificationActionType, action.type); | 122 EXPECT_EQ(kWebNotificationActionType, action.type); |
| 123 EXPECT_EQ(kNotificationActionAction, action.action); | 123 EXPECT_EQ(kNotificationActionAction, action.action); |
| 124 EXPECT_EQ(kNotificationActionTitle, action.title); | 124 EXPECT_EQ(kNotificationActionTitle, action.title); |
| 125 EXPECT_EQ(kNotificationActionPlaceholder, action.placeholder); | 125 EXPECT_EQ(kNotificationActionPlaceholder, action.placeholder); |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 TEST_F(NotificationDataTest, SilentNotificationWithVibration) { | 129 TEST_F(NotificationDataTest, SilentNotificationWithVibration) { |
| 130 Vector<unsigned> vibrationPattern; | 130 Vector<unsigned> vibrationPattern; |
| 131 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNotificationVibration); ++i) | 131 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNotificationVibration); ++i) |
| 132 vibrationPattern.append(kNotificationVibration[i]); | 132 vibrationPattern.push_back(kNotificationVibration[i]); |
| 133 | 133 |
| 134 UnsignedLongOrUnsignedLongSequence vibrationSequence; | 134 UnsignedLongOrUnsignedLongSequence vibrationSequence; |
| 135 vibrationSequence.setUnsignedLongSequence(vibrationPattern); | 135 vibrationSequence.setUnsignedLongSequence(vibrationPattern); |
| 136 | 136 |
| 137 NotificationOptions options; | 137 NotificationOptions options; |
| 138 options.setVibrate(vibrationSequence); | 138 options.setVibrate(vibrationSequence); |
| 139 options.setSilent(true); | 139 options.setSilent(true); |
| 140 | 140 |
| 141 DummyExceptionStateForTesting exceptionState; | 141 DummyExceptionStateForTesting exceptionState; |
| 142 WebNotificationData notificationData = createWebNotificationData( | 142 WebNotificationData notificationData = createWebNotificationData( |
| 143 getExecutionContext(), kNotificationTitle, options, exceptionState); | 143 getExecutionContext(), kNotificationTitle, options, exceptionState); |
| 144 ASSERT_TRUE(exceptionState.hadException()); | 144 ASSERT_TRUE(exceptionState.hadException()); |
| 145 | 145 |
| 146 EXPECT_EQ("Silent notifications must not specify vibration patterns.", | 146 EXPECT_EQ("Silent notifications must not specify vibration patterns.", |
| 147 exceptionState.message()); | 147 exceptionState.message()); |
| 148 } | 148 } |
| 149 | 149 |
| 150 TEST_F(NotificationDataTest, ActionTypeButtonWithPlaceholder) { | 150 TEST_F(NotificationDataTest, ActionTypeButtonWithPlaceholder) { |
| 151 HeapVector<NotificationAction> actions; | 151 HeapVector<NotificationAction> actions; |
| 152 NotificationAction action; | 152 NotificationAction action; |
| 153 action.setType("button"); | 153 action.setType("button"); |
| 154 action.setPlaceholder("I'm afraid I can't do that..."); | 154 action.setPlaceholder("I'm afraid I can't do that..."); |
| 155 actions.append(action); | 155 actions.push_back(action); |
| 156 | 156 |
| 157 NotificationOptions options; | 157 NotificationOptions options; |
| 158 options.setActions(actions); | 158 options.setActions(actions); |
| 159 | 159 |
| 160 DummyExceptionStateForTesting exceptionState; | 160 DummyExceptionStateForTesting exceptionState; |
| 161 WebNotificationData notificationData = createWebNotificationData( | 161 WebNotificationData notificationData = createWebNotificationData( |
| 162 getExecutionContext(), kNotificationTitle, options, exceptionState); | 162 getExecutionContext(), kNotificationTitle, options, exceptionState); |
| 163 ASSERT_TRUE(exceptionState.hadException()); | 163 ASSERT_TRUE(exceptionState.hadException()); |
| 164 | 164 |
| 165 EXPECT_EQ("Notifications of type \"button\" cannot specify a placeholder.", | 165 EXPECT_EQ("Notifications of type \"button\" cannot specify a placeholder.", |
| (...skipping 15 matching lines...) Expand all Loading... |
| 181 exceptionState.message()); | 181 exceptionState.message()); |
| 182 } | 182 } |
| 183 | 183 |
| 184 TEST_F(NotificationDataTest, InvalidIconUrls) { | 184 TEST_F(NotificationDataTest, InvalidIconUrls) { |
| 185 HeapVector<NotificationAction> actions; | 185 HeapVector<NotificationAction> actions; |
| 186 for (size_t i = 0; i < Notification::maxActions(); ++i) { | 186 for (size_t i = 0; i < Notification::maxActions(); ++i) { |
| 187 NotificationAction action; | 187 NotificationAction action; |
| 188 action.setAction(kNotificationActionAction); | 188 action.setAction(kNotificationActionAction); |
| 189 action.setTitle(kNotificationActionTitle); | 189 action.setTitle(kNotificationActionTitle); |
| 190 action.setIcon(kNotificationIconInvalid); | 190 action.setIcon(kNotificationIconInvalid); |
| 191 actions.append(action); | 191 actions.push_back(action); |
| 192 } | 192 } |
| 193 | 193 |
| 194 NotificationOptions options; | 194 NotificationOptions options; |
| 195 options.setImage(kNotificationIconInvalid); | 195 options.setImage(kNotificationIconInvalid); |
| 196 options.setIcon(kNotificationIconInvalid); | 196 options.setIcon(kNotificationIconInvalid); |
| 197 options.setBadge(kNotificationIconInvalid); | 197 options.setBadge(kNotificationIconInvalid); |
| 198 options.setActions(actions); | 198 options.setActions(actions); |
| 199 | 199 |
| 200 DummyExceptionStateForTesting exceptionState; | 200 DummyExceptionStateForTesting exceptionState; |
| 201 WebNotificationData notificationData = createWebNotificationData( | 201 WebNotificationData notificationData = createWebNotificationData( |
| 202 getExecutionContext(), kNotificationTitle, options, exceptionState); | 202 getExecutionContext(), kNotificationTitle, options, exceptionState); |
| 203 ASSERT_FALSE(exceptionState.hadException()); | 203 ASSERT_FALSE(exceptionState.hadException()); |
| 204 | 204 |
| 205 EXPECT_TRUE(notificationData.image.isEmpty()); | 205 EXPECT_TRUE(notificationData.image.isEmpty()); |
| 206 EXPECT_TRUE(notificationData.icon.isEmpty()); | 206 EXPECT_TRUE(notificationData.icon.isEmpty()); |
| 207 EXPECT_TRUE(notificationData.badge.isEmpty()); | 207 EXPECT_TRUE(notificationData.badge.isEmpty()); |
| 208 for (const auto& action : notificationData.actions) | 208 for (const auto& action : notificationData.actions) |
| 209 EXPECT_TRUE(action.icon.isEmpty()); | 209 EXPECT_TRUE(action.icon.isEmpty()); |
| 210 } | 210 } |
| 211 | 211 |
| 212 TEST_F(NotificationDataTest, VibrationNormalization) { | 212 TEST_F(NotificationDataTest, VibrationNormalization) { |
| 213 Vector<unsigned> unnormalizedPattern; | 213 Vector<unsigned> unnormalizedPattern; |
| 214 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNotificationVibrationUnnormalized); | 214 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNotificationVibrationUnnormalized); |
| 215 ++i) | 215 ++i) |
| 216 unnormalizedPattern.append(kNotificationVibrationUnnormalized[i]); | 216 unnormalizedPattern.push_back(kNotificationVibrationUnnormalized[i]); |
| 217 | 217 |
| 218 UnsignedLongOrUnsignedLongSequence vibrationSequence; | 218 UnsignedLongOrUnsignedLongSequence vibrationSequence; |
| 219 vibrationSequence.setUnsignedLongSequence(unnormalizedPattern); | 219 vibrationSequence.setUnsignedLongSequence(unnormalizedPattern); |
| 220 | 220 |
| 221 NotificationOptions options; | 221 NotificationOptions options; |
| 222 options.setVibrate(vibrationSequence); | 222 options.setVibrate(vibrationSequence); |
| 223 | 223 |
| 224 DummyExceptionStateForTesting exceptionState; | 224 DummyExceptionStateForTesting exceptionState; |
| 225 WebNotificationData notificationData = createWebNotificationData( | 225 WebNotificationData notificationData = createWebNotificationData( |
| 226 getExecutionContext(), kNotificationTitle, options, exceptionState); | 226 getExecutionContext(), kNotificationTitle, options, exceptionState); |
| 227 EXPECT_FALSE(exceptionState.hadException()); | 227 EXPECT_FALSE(exceptionState.hadException()); |
| 228 | 228 |
| 229 Vector<int> normalizedPattern; | 229 Vector<int> normalizedPattern; |
| 230 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNotificationVibrationNormalized); | 230 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNotificationVibrationNormalized); |
| 231 ++i) | 231 ++i) |
| 232 normalizedPattern.append(kNotificationVibrationNormalized[i]); | 232 normalizedPattern.push_back(kNotificationVibrationNormalized[i]); |
| 233 | 233 |
| 234 ASSERT_EQ(normalizedPattern.size(), notificationData.vibrate.size()); | 234 ASSERT_EQ(normalizedPattern.size(), notificationData.vibrate.size()); |
| 235 for (size_t i = 0; i < normalizedPattern.size(); ++i) | 235 for (size_t i = 0; i < normalizedPattern.size(); ++i) |
| 236 EXPECT_EQ(normalizedPattern[i], notificationData.vibrate[i]); | 236 EXPECT_EQ(normalizedPattern[i], notificationData.vibrate[i]); |
| 237 } | 237 } |
| 238 | 238 |
| 239 TEST_F(NotificationDataTest, DefaultTimestampValue) { | 239 TEST_F(NotificationDataTest, DefaultTimestampValue) { |
| 240 NotificationOptions options; | 240 NotificationOptions options; |
| 241 | 241 |
| 242 DummyExceptionStateForTesting exceptionState; | 242 DummyExceptionStateForTesting exceptionState; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 272 } | 272 } |
| 273 } | 273 } |
| 274 | 274 |
| 275 TEST_F(NotificationDataTest, MaximumActionCount) { | 275 TEST_F(NotificationDataTest, MaximumActionCount) { |
| 276 HeapVector<NotificationAction> actions; | 276 HeapVector<NotificationAction> actions; |
| 277 for (size_t i = 0; i < Notification::maxActions() + 2; ++i) { | 277 for (size_t i = 0; i < Notification::maxActions() + 2; ++i) { |
| 278 NotificationAction action; | 278 NotificationAction action; |
| 279 action.setAction(String::number(i)); | 279 action.setAction(String::number(i)); |
| 280 action.setTitle(kNotificationActionTitle); | 280 action.setTitle(kNotificationActionTitle); |
| 281 | 281 |
| 282 actions.append(action); | 282 actions.push_back(action); |
| 283 } | 283 } |
| 284 | 284 |
| 285 NotificationOptions options; | 285 NotificationOptions options; |
| 286 options.setActions(actions); | 286 options.setActions(actions); |
| 287 | 287 |
| 288 DummyExceptionStateForTesting exceptionState; | 288 DummyExceptionStateForTesting exceptionState; |
| 289 WebNotificationData notificationData = createWebNotificationData( | 289 WebNotificationData notificationData = createWebNotificationData( |
| 290 getExecutionContext(), kNotificationTitle, options, exceptionState); | 290 getExecutionContext(), kNotificationTitle, options, exceptionState); |
| 291 ASSERT_FALSE(exceptionState.hadException()); | 291 ASSERT_FALSE(exceptionState.hadException()); |
| 292 | 292 |
| 293 // The stored actions will be capped to |maxActions| entries. | 293 // The stored actions will be capped to |maxActions| entries. |
| 294 ASSERT_EQ(Notification::maxActions(), notificationData.actions.size()); | 294 ASSERT_EQ(Notification::maxActions(), notificationData.actions.size()); |
| 295 | 295 |
| 296 for (size_t i = 0; i < Notification::maxActions(); ++i) { | 296 for (size_t i = 0; i < Notification::maxActions(); ++i) { |
| 297 WebString expectedAction = String::number(i); | 297 WebString expectedAction = String::number(i); |
| 298 EXPECT_EQ(expectedAction, notificationData.actions[i].action); | 298 EXPECT_EQ(expectedAction, notificationData.actions[i].action); |
| 299 } | 299 } |
| 300 } | 300 } |
| 301 | 301 |
| 302 } // namespace | 302 } // namespace |
| 303 } // namespace blink | 303 } // namespace blink |
| OLD | NEW |