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" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "wtf/CurrentTime.h" | 12 #include "wtf/CurrentTime.h" |
13 #include "wtf/HashMap.h" | 13 #include "wtf/HashMap.h" |
14 #include "wtf/Vector.h" | 14 #include "wtf/Vector.h" |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 namespace { | 17 namespace { |
18 | 18 |
19 const char kNotificationTitle[] = "My Notification"; | 19 const char kNotificationTitle[] = "My Notification"; |
20 | 20 |
21 const char kNotificationDir[] = "rtl"; | 21 const char kNotificationDir[] = "rtl"; |
22 const char kNotificationLang[] = "nl"; | 22 const char kNotificationLang[] = "nl"; |
23 const char kNotificationBody[] = "Hello, world"; | 23 const char kNotificationBody[] = "Hello, world"; |
24 const char kNotificationTag[] = "my_tag"; | 24 const char kNotificationTag[] = "my_tag"; |
25 const char kNotificationEmptyTag[] = ""; | 25 const char kNotificationEmptyTag[] = ""; |
26 const char kNotificationImage[] = "https://example.com/image.jpg"; | |
26 const char kNotificationIcon[] = "https://example.com/icon.png"; | 27 const char kNotificationIcon[] = "https://example.com/icon.png"; |
27 const char kNotificationIconInvalid[] = "https://invalid:icon:url"; | 28 const char kNotificationIconInvalid[] = "https://invalid:icon:url"; |
28 const char kNotificationBadge[] = "https://example.com/badge.png"; | 29 const char kNotificationBadge[] = "https://example.com/badge.png"; |
29 const unsigned kNotificationVibration[] = { 42, 10, 20, 30, 40 }; | 30 const unsigned kNotificationVibration[] = { 42, 10, 20, 30, 40 }; |
30 const unsigned long long kNotificationTimestamp = 621046800ull; | 31 const unsigned long long kNotificationTimestamp = 621046800ull; |
31 const bool kNotificationRenotify = true; | 32 const bool kNotificationRenotify = true; |
32 const bool kNotificationSilent = false; | 33 const bool kNotificationSilent = false; |
33 const bool kNotificationRequireInteraction = true; | 34 const bool kNotificationRequireInteraction = true; |
34 | 35 |
35 const WebNotificationAction::Type kWebNotificationActionType = WebNotificationAc tion::Text; | 36 const WebNotificationAction::Type kWebNotificationActionType = WebNotificationAc tion::Text; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 action.setPlaceholder(kNotificationActionPlaceholder); | 75 action.setPlaceholder(kNotificationActionPlaceholder); |
75 | 76 |
76 actions.append(action); | 77 actions.append(action); |
77 } | 78 } |
78 | 79 |
79 NotificationOptions options; | 80 NotificationOptions options; |
80 options.setDir(kNotificationDir); | 81 options.setDir(kNotificationDir); |
81 options.setLang(kNotificationLang); | 82 options.setLang(kNotificationLang); |
82 options.setBody(kNotificationBody); | 83 options.setBody(kNotificationBody); |
83 options.setTag(kNotificationTag); | 84 options.setTag(kNotificationTag); |
85 options.setImage(kNotificationImage); | |
84 options.setIcon(kNotificationIcon); | 86 options.setIcon(kNotificationIcon); |
85 options.setBadge(kNotificationBadge); | 87 options.setBadge(kNotificationBadge); |
86 options.setVibrate(vibrationSequence); | 88 options.setVibrate(vibrationSequence); |
87 options.setTimestamp(kNotificationTimestamp); | 89 options.setTimestamp(kNotificationTimestamp); |
88 options.setRenotify(kNotificationRenotify); | 90 options.setRenotify(kNotificationRenotify); |
89 options.setSilent(kNotificationSilent); | 91 options.setSilent(kNotificationSilent); |
90 options.setRequireInteraction(kNotificationRequireInteraction); | 92 options.setRequireInteraction(kNotificationRequireInteraction); |
91 options.setActions(actions); | 93 options.setActions(actions); |
92 | 94 |
93 // TODO(peter): Test |options.data| and |notificationData.data|. | 95 // TODO(peter): Test |options.data| and |notificationData.data|. |
(...skipping 10 matching lines...) Expand all Loading... | |
104 EXPECT_EQ(kNotificationTag, notificationData.tag); | 106 EXPECT_EQ(kNotificationTag, notificationData.tag); |
105 | 107 |
106 // TODO(peter): Test the various icon properties when ExecutionContext::comp leteURL() works in this test. | 108 // TODO(peter): Test the various icon properties when ExecutionContext::comp leteURL() works in this test. |
107 | 109 |
108 ASSERT_EQ(vibrationPattern.size(), notificationData.vibrate.size()); | 110 ASSERT_EQ(vibrationPattern.size(), notificationData.vibrate.size()); |
109 for (size_t i = 0; i < vibrationPattern.size(); ++i) | 111 for (size_t i = 0; i < vibrationPattern.size(); ++i) |
110 EXPECT_EQ(vibrationPattern[i], static_cast<unsigned>(notificationData.vi brate[i])); | 112 EXPECT_EQ(vibrationPattern[i], static_cast<unsigned>(notificationData.vi brate[i])); |
111 | 113 |
112 EXPECT_EQ(kNotificationTimestamp, notificationData.timestamp); | 114 EXPECT_EQ(kNotificationTimestamp, notificationData.timestamp); |
113 EXPECT_EQ(kNotificationRenotify, notificationData.renotify); | 115 EXPECT_EQ(kNotificationRenotify, notificationData.renotify); |
114 EXPECT_EQ(kNotificationSilent, notificationData.silent); | 116 EXPECT_EQ(kNotificationSilent, notificationData.silent); |
Peter Beverloo
2016/08/22 20:11:07
+EXPECT_EQ for the image
johnme
2016/08/23 14:59:49
I matched the TODO above: "// TODO(peter): Test th
| |
115 EXPECT_EQ(kNotificationRequireInteraction, notificationData.requireInteracti on); | 117 EXPECT_EQ(kNotificationRequireInteraction, notificationData.requireInteracti on); |
116 EXPECT_EQ(actions.size(), notificationData.actions.size()); | 118 EXPECT_EQ(actions.size(), notificationData.actions.size()); |
117 for (const auto& action : notificationData.actions) { | 119 for (const auto& action : notificationData.actions) { |
118 EXPECT_EQ(kWebNotificationActionType, action.type); | 120 EXPECT_EQ(kWebNotificationActionType, action.type); |
119 EXPECT_EQ(kNotificationActionAction, action.action); | 121 EXPECT_EQ(kNotificationActionAction, action.action); |
120 EXPECT_EQ(kNotificationActionTitle, action.title); | 122 EXPECT_EQ(kNotificationActionTitle, action.title); |
121 EXPECT_EQ(kNotificationActionPlaceholder, action.placeholder); | 123 EXPECT_EQ(kNotificationActionPlaceholder, action.placeholder); |
122 } | 124 } |
123 } | 125 } |
124 | 126 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 HeapVector<NotificationAction> actions; | 180 HeapVector<NotificationAction> actions; |
179 for (size_t i = 0; i < Notification::maxActions(); ++i) { | 181 for (size_t i = 0; i < Notification::maxActions(); ++i) { |
180 NotificationAction action; | 182 NotificationAction action; |
181 action.setAction(kNotificationActionAction); | 183 action.setAction(kNotificationActionAction); |
182 action.setTitle(kNotificationActionTitle); | 184 action.setTitle(kNotificationActionTitle); |
183 action.setIcon(kNotificationIconInvalid); | 185 action.setIcon(kNotificationIconInvalid); |
184 actions.append(action); | 186 actions.append(action); |
185 } | 187 } |
186 | 188 |
187 NotificationOptions options; | 189 NotificationOptions options; |
190 options.setImage(kNotificationIconInvalid); | |
188 options.setIcon(kNotificationIconInvalid); | 191 options.setIcon(kNotificationIconInvalid); |
189 options.setBadge(kNotificationIconInvalid); | 192 options.setBadge(kNotificationIconInvalid); |
190 options.setActions(actions); | 193 options.setActions(actions); |
191 | 194 |
192 TrackExceptionState exceptionState; | 195 TrackExceptionState exceptionState; |
193 WebNotificationData notificationData = createWebNotificationData(getExecutio nContext(), kNotificationTitle, options, exceptionState); | 196 WebNotificationData notificationData = createWebNotificationData(getExecutio nContext(), kNotificationTitle, options, exceptionState); |
194 ASSERT_FALSE(exceptionState.hadException()); | 197 ASSERT_FALSE(exceptionState.hadException()); |
195 | 198 |
199 EXPECT_TRUE(notificationData.image.isEmpty()); | |
196 EXPECT_TRUE(notificationData.icon.isEmpty()); | 200 EXPECT_TRUE(notificationData.icon.isEmpty()); |
197 EXPECT_TRUE(notificationData.badge.isEmpty()); | 201 EXPECT_TRUE(notificationData.badge.isEmpty()); |
198 for (const auto& action : notificationData.actions) | 202 for (const auto& action : notificationData.actions) |
199 EXPECT_TRUE(action.icon.isEmpty()); | 203 EXPECT_TRUE(action.icon.isEmpty()); |
200 } | 204 } |
201 | 205 |
202 TEST_F(NotificationDataTest, VibrationNormalization) | 206 TEST_F(NotificationDataTest, VibrationNormalization) |
203 { | 207 { |
204 Vector<unsigned> unnormalizedPattern; | 208 Vector<unsigned> unnormalizedPattern; |
205 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNotificationVibrationUnnormalized); ++i) | 209 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNotificationVibrationUnnormalized); ++i) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 ASSERT_EQ(Notification::maxActions(), notificationData.actions.size()); | 285 ASSERT_EQ(Notification::maxActions(), notificationData.actions.size()); |
282 | 286 |
283 for (size_t i = 0; i < Notification::maxActions(); ++i) { | 287 for (size_t i = 0; i < Notification::maxActions(); ++i) { |
284 WebString expectedAction = String::number(i); | 288 WebString expectedAction = String::number(i); |
285 EXPECT_EQ(expectedAction, notificationData.actions[i].action); | 289 EXPECT_EQ(expectedAction, notificationData.actions[i].action); |
286 } | 290 } |
287 } | 291 } |
288 | 292 |
289 } // namespace | 293 } // namespace |
290 } // namespace blink | 294 } // namespace blink |
OLD | NEW |