| 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 "bindings/modules/v8/UnionTypesModules.h" | 8 #include "bindings/modules/v8/UnionTypesModules.h" |
| 9 #include "core/testing/NullExecutionContext.h" | 9 #include "core/testing/NullExecutionContext.h" |
| 10 #include "modules/notifications/Notification.h" | 10 #include "modules/notifications/Notification.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 const char kNotificationEmptyTag[] = ""; | 26 const char kNotificationEmptyTag[] = ""; |
| 27 const char kNotificationIcon[] = "https://example.com/icon.png"; | 27 const char kNotificationIcon[] = "https://example.com/icon.png"; |
| 28 const char kNotificationIconInvalid[] = "https://invalid:icon:url"; | 28 const char kNotificationIconInvalid[] = "https://invalid:icon:url"; |
| 29 const char kNotificationBadge[] = "https://example.com/badge.png"; | 29 const char kNotificationBadge[] = "https://example.com/badge.png"; |
| 30 const unsigned kNotificationVibration[] = { 42, 10, 20, 30, 40 }; | 30 const unsigned kNotificationVibration[] = { 42, 10, 20, 30, 40 }; |
| 31 const unsigned long long kNotificationTimestamp = 621046800ull; | 31 const unsigned long long kNotificationTimestamp = 621046800ull; |
| 32 const bool kNotificationRenotify = true; | 32 const bool kNotificationRenotify = true; |
| 33 const bool kNotificationSilent = false; | 33 const bool kNotificationSilent = false; |
| 34 const bool kNotificationRequireInteraction = true; | 34 const bool kNotificationRequireInteraction = true; |
| 35 | 35 |
| 36 const WebNotificationAction::Type kWebNotificationActionType = WebNotificationAc
tion::Text; |
| 37 const char kNotificationActionType[] = "text"; |
| 36 const char kNotificationActionAction[] = "my_action"; | 38 const char kNotificationActionAction[] = "my_action"; |
| 37 const char kNotificationActionTitle[] = "My Action"; | 39 const char kNotificationActionTitle[] = "My Action"; |
| 38 const char kNotificationActionIcon[] = "https://example.com/action_icon.png"; | 40 const char kNotificationActionIcon[] = "https://example.com/action_icon.png"; |
| 41 const char kNotificationActionPlaceholder[] = "Placeholder..."; |
| 39 | 42 |
| 40 const unsigned kNotificationVibrationUnnormalized[] = { 10, 1000000, 50, 42 }; | 43 const unsigned kNotificationVibrationUnnormalized[] = { 10, 1000000, 50, 42 }; |
| 41 const int kNotificationVibrationNormalized[] = { 10, 10000, 50 }; | 44 const int kNotificationVibrationNormalized[] = { 10, 10000, 50 }; |
| 42 | 45 |
| 43 class NotificationDataTest : public ::testing::Test { | 46 class NotificationDataTest : public ::testing::Test { |
| 44 public: | 47 public: |
| 45 void SetUp() override | 48 void SetUp() override |
| 46 { | 49 { |
| 47 m_executionContext = new NullExecutionContext(); | 50 m_executionContext = new NullExecutionContext(); |
| 48 } | 51 } |
| 49 | 52 |
| 50 ExecutionContext* getExecutionContext() { return m_executionContext.get(); } | 53 ExecutionContext* getExecutionContext() { return m_executionContext.get(); } |
| 51 | 54 |
| 52 private: | 55 private: |
| 53 Persistent<ExecutionContext> m_executionContext; | 56 Persistent<ExecutionContext> m_executionContext; |
| 54 }; | 57 }; |
| 55 | 58 |
| 56 TEST_F(NotificationDataTest, ReflectProperties) | 59 TEST_F(NotificationDataTest, ReflectProperties) |
| 57 { | 60 { |
| 58 Vector<unsigned> vibrationPattern; | 61 Vector<unsigned> vibrationPattern; |
| 59 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNotificationVibration); ++i) | 62 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNotificationVibration); ++i) |
| 60 vibrationPattern.append(kNotificationVibration[i]); | 63 vibrationPattern.append(kNotificationVibration[i]); |
| 61 | 64 |
| 62 UnsignedLongOrUnsignedLongSequence vibrationSequence; | 65 UnsignedLongOrUnsignedLongSequence vibrationSequence; |
| 63 vibrationSequence.setUnsignedLongSequence(vibrationPattern); | 66 vibrationSequence.setUnsignedLongSequence(vibrationPattern); |
| 64 | 67 |
| 65 HeapVector<NotificationAction> actions; | 68 HeapVector<NotificationAction> actions; |
| 66 for (size_t i = 0; i < Notification::maxActions(); ++i) { | 69 for (size_t i = 0; i < Notification::maxActions(); ++i) { |
| 67 NotificationAction action; | 70 NotificationAction action; |
| 71 action.setType(kNotificationActionType); |
| 68 action.setAction(kNotificationActionAction); | 72 action.setAction(kNotificationActionAction); |
| 69 action.setTitle(kNotificationActionTitle); | 73 action.setTitle(kNotificationActionTitle); |
| 70 action.setIcon(kNotificationActionIcon); | 74 action.setIcon(kNotificationActionIcon); |
| 75 action.setPlaceholder(kNotificationActionPlaceholder); |
| 71 | 76 |
| 72 actions.append(action); | 77 actions.append(action); |
| 73 } | 78 } |
| 74 | 79 |
| 75 NotificationOptions options; | 80 NotificationOptions options; |
| 76 options.setDir(kNotificationDir); | 81 options.setDir(kNotificationDir); |
| 77 options.setLang(kNotificationLang); | 82 options.setLang(kNotificationLang); |
| 78 options.setBody(kNotificationBody); | 83 options.setBody(kNotificationBody); |
| 79 options.setTag(kNotificationTag); | 84 options.setTag(kNotificationTag); |
| 80 options.setIcon(kNotificationIcon); | 85 options.setIcon(kNotificationIcon); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 104 ASSERT_EQ(vibrationPattern.size(), notificationData.vibrate.size()); | 109 ASSERT_EQ(vibrationPattern.size(), notificationData.vibrate.size()); |
| 105 for (size_t i = 0; i < vibrationPattern.size(); ++i) | 110 for (size_t i = 0; i < vibrationPattern.size(); ++i) |
| 106 EXPECT_EQ(vibrationPattern[i], static_cast<unsigned>(notificationData.vi
brate[i])); | 111 EXPECT_EQ(vibrationPattern[i], static_cast<unsigned>(notificationData.vi
brate[i])); |
| 107 | 112 |
| 108 EXPECT_EQ(kNotificationTimestamp, notificationData.timestamp); | 113 EXPECT_EQ(kNotificationTimestamp, notificationData.timestamp); |
| 109 EXPECT_EQ(kNotificationRenotify, notificationData.renotify); | 114 EXPECT_EQ(kNotificationRenotify, notificationData.renotify); |
| 110 EXPECT_EQ(kNotificationSilent, notificationData.silent); | 115 EXPECT_EQ(kNotificationSilent, notificationData.silent); |
| 111 EXPECT_EQ(kNotificationRequireInteraction, notificationData.requireInteracti
on); | 116 EXPECT_EQ(kNotificationRequireInteraction, notificationData.requireInteracti
on); |
| 112 EXPECT_EQ(actions.size(), notificationData.actions.size()); | 117 EXPECT_EQ(actions.size(), notificationData.actions.size()); |
| 113 for (const auto& action : notificationData.actions) { | 118 for (const auto& action : notificationData.actions) { |
| 119 EXPECT_EQ(kWebNotificationActionType, action.type); |
| 114 EXPECT_EQ(kNotificationActionAction, action.action); | 120 EXPECT_EQ(kNotificationActionAction, action.action); |
| 115 EXPECT_EQ(kNotificationActionTitle, action.title); | 121 EXPECT_EQ(kNotificationActionTitle, action.title); |
| 122 EXPECT_EQ(kNotificationActionPlaceholder, action.placeholder); |
| 116 } | 123 } |
| 117 } | 124 } |
| 118 | 125 |
| 119 TEST_F(NotificationDataTest, SilentNotificationWithVibration) | 126 TEST_F(NotificationDataTest, SilentNotificationWithVibration) |
| 120 { | 127 { |
| 121 Vector<unsigned> vibrationPattern; | 128 Vector<unsigned> vibrationPattern; |
| 122 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNotificationVibration); ++i) | 129 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNotificationVibration); ++i) |
| 123 vibrationPattern.append(kNotificationVibration[i]); | 130 vibrationPattern.append(kNotificationVibration[i]); |
| 124 | 131 |
| 125 UnsignedLongOrUnsignedLongSequence vibrationSequence; | 132 UnsignedLongOrUnsignedLongSequence vibrationSequence; |
| 126 vibrationSequence.setUnsignedLongSequence(vibrationPattern); | 133 vibrationSequence.setUnsignedLongSequence(vibrationPattern); |
| 127 | 134 |
| 128 NotificationOptions options; | 135 NotificationOptions options; |
| 129 options.setVibrate(vibrationSequence); | 136 options.setVibrate(vibrationSequence); |
| 130 options.setSilent(true); | 137 options.setSilent(true); |
| 131 | 138 |
| 132 TrackExceptionState exceptionState; | 139 TrackExceptionState exceptionState; |
| 133 WebNotificationData notificationData = createWebNotificationData(getExecutio
nContext(), kNotificationTitle, options, exceptionState); | 140 WebNotificationData notificationData = createWebNotificationData(getExecutio
nContext(), kNotificationTitle, options, exceptionState); |
| 134 ASSERT_TRUE(exceptionState.hadException()); | 141 ASSERT_TRUE(exceptionState.hadException()); |
| 135 | 142 |
| 136 EXPECT_EQ("Silent notifications must not specify vibration patterns.", excep
tionState.message()); | 143 EXPECT_EQ("Silent notifications must not specify vibration patterns.", excep
tionState.message()); |
| 137 } | 144 } |
| 138 | 145 |
| 146 TEST_F(NotificationDataTest, ActionTypeButtonWithPlaceholder) |
| 147 { |
| 148 HeapVector<NotificationAction> actions; |
| 149 NotificationAction action; |
| 150 action.setType("button"); |
| 151 action.setPlaceholder("I'm afraid I can't do that..."); |
| 152 actions.append(action); |
| 153 |
| 154 NotificationOptions options; |
| 155 options.setActions(actions); |
| 156 |
| 157 TrackExceptionState exceptionState; |
| 158 WebNotificationData notificationData = createWebNotificationData(getExecutio
nContext(), kNotificationTitle, options, exceptionState); |
| 159 ASSERT_TRUE(exceptionState.hadException()); |
| 160 |
| 161 EXPECT_EQ("Notifications of type \"button\" cannot specify a placeholder.",
exceptionState.message()); |
| 162 } |
| 163 |
| 139 TEST_F(NotificationDataTest, RenotifyWithEmptyTag) | 164 TEST_F(NotificationDataTest, RenotifyWithEmptyTag) |
| 140 { | 165 { |
| 141 NotificationOptions options; | 166 NotificationOptions options; |
| 142 options.setTag(kNotificationEmptyTag); | 167 options.setTag(kNotificationEmptyTag); |
| 143 options.setRenotify(true); | 168 options.setRenotify(true); |
| 144 | 169 |
| 145 TrackExceptionState exceptionState; | 170 TrackExceptionState exceptionState; |
| 146 WebNotificationData notificationData = createWebNotificationData(getExecutio
nContext(), kNotificationTitle, options, exceptionState); | 171 WebNotificationData notificationData = createWebNotificationData(getExecutio
nContext(), kNotificationTitle, options, exceptionState); |
| 147 ASSERT_TRUE(exceptionState.hadException()); | 172 ASSERT_TRUE(exceptionState.hadException()); |
| 148 | 173 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 ASSERT_EQ(Notification::maxActions(), notificationData.actions.size()); | 282 ASSERT_EQ(Notification::maxActions(), notificationData.actions.size()); |
| 258 | 283 |
| 259 for (size_t i = 0; i < Notification::maxActions(); ++i) { | 284 for (size_t i = 0; i < Notification::maxActions(); ++i) { |
| 260 WebString expectedAction = String::number(i); | 285 WebString expectedAction = String::number(i); |
| 261 EXPECT_EQ(expectedAction, notificationData.actions[i].action); | 286 EXPECT_EQ(expectedAction, notificationData.actions[i].action); |
| 262 } | 287 } |
| 263 } | 288 } |
| 264 | 289 |
| 265 } // namespace | 290 } // namespace |
| 266 } // namespace blink | 291 } // namespace blink |
| OLD | NEW |