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

Side by Side Diff: third_party/WebKit/Source/modules/notifications/NotificationDataTest.cpp

Issue 1388483002: Implement the Notification `timestamp` property (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 "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"
11 #include "modules/notifications/Notification.h" 11 #include "modules/notifications/Notification.h"
12 #include "modules/notifications/NotificationOptions.h" 12 #include "modules/notifications/NotificationOptions.h"
13 #include "wtf/CurrentTime.h"
13 #include "wtf/HashMap.h" 14 #include "wtf/HashMap.h"
14 #include "wtf/Vector.h" 15 #include "wtf/Vector.h"
15 #include <gtest/gtest.h> 16 #include <gtest/gtest.h>
16 17
17 namespace blink { 18 namespace blink {
18 namespace { 19 namespace {
19 20
20 const char kNotificationTitle[] = "My Notification"; 21 const char kNotificationTitle[] = "My Notification";
21 22
22 const char kNotificationDir[] = "rtl"; 23 const char kNotificationDir[] = "rtl";
23 const char kNotificationLang[] = "nl"; 24 const char kNotificationLang[] = "nl";
24 const char kNotificationBody[] = "Hello, world"; 25 const char kNotificationBody[] = "Hello, world";
25 const char kNotificationTag[] = "my_tag"; 26 const char kNotificationTag[] = "my_tag";
26 const char kNotificationIcon[] = "https://example.com/icon.png"; 27 const char kNotificationIcon[] = "https://example.com/icon.png";
27 const unsigned kNotificationVibration[] = { 42, 10, 20, 30, 40 }; 28 const unsigned kNotificationVibration[] = { 42, 10, 20, 30, 40 };
29 const unsigned long long kNotificationTimestamp = 621046800ull;
28 const bool kNotificationSilent = false; 30 const bool kNotificationSilent = false;
29 const bool kNotificationRequireInteraction = true; 31 const bool kNotificationRequireInteraction = true;
30 32
31 const char kNotificationActionAction[] = "my_action"; 33 const char kNotificationActionAction[] = "my_action";
32 const char kNotificationActionTitle[] = "My Action"; 34 const char kNotificationActionTitle[] = "My Action";
33 35
34 const unsigned kNotificationVibrationUnnormalized[] = { 10, 1000000, 50, 42 }; 36 const unsigned kNotificationVibrationUnnormalized[] = { 10, 1000000, 50, 42 };
35 const int kNotificationVibrationNormalized[] = { 10, 10000, 50 }; 37 const int kNotificationVibrationNormalized[] = { 10, 10000, 50 };
36 38
37 class NotificationDataTest : public ::testing::Test { 39 class NotificationDataTest : public ::testing::Test {
(...skipping 27 matching lines...) Expand all
65 actions.append(action); 67 actions.append(action);
66 } 68 }
67 69
68 NotificationOptions options; 70 NotificationOptions options;
69 options.setDir(kNotificationDir); 71 options.setDir(kNotificationDir);
70 options.setLang(kNotificationLang); 72 options.setLang(kNotificationLang);
71 options.setBody(kNotificationBody); 73 options.setBody(kNotificationBody);
72 options.setTag(kNotificationTag); 74 options.setTag(kNotificationTag);
73 options.setIcon(kNotificationIcon); 75 options.setIcon(kNotificationIcon);
74 options.setVibrate(vibrationSequence); 76 options.setVibrate(vibrationSequence);
77 options.setTimestamp(kNotificationTimestamp);
75 options.setSilent(kNotificationSilent); 78 options.setSilent(kNotificationSilent);
76 options.setRequireInteraction(kNotificationRequireInteraction); 79 options.setRequireInteraction(kNotificationRequireInteraction);
77 options.setActions(actions); 80 options.setActions(actions);
78 81
79 // TODO(peter): Test |options.data| and |notificationData.data|. 82 // TODO(peter): Test |options.data| and |notificationData.data|.
80 83
81 TrackExceptionState exceptionState; 84 TrackExceptionState exceptionState;
82 WebNotificationData notificationData = createWebNotificationData(executionCo ntext(), kNotificationTitle, options, exceptionState); 85 WebNotificationData notificationData = createWebNotificationData(executionCo ntext(), kNotificationTitle, options, exceptionState);
83 ASSERT_FALSE(exceptionState.hadException()); 86 ASSERT_FALSE(exceptionState.hadException());
84 87
85 EXPECT_EQ(kNotificationTitle, notificationData.title); 88 EXPECT_EQ(kNotificationTitle, notificationData.title);
86 89
87 EXPECT_EQ(WebNotificationData::DirectionRightToLeft, notificationData.direct ion); 90 EXPECT_EQ(WebNotificationData::DirectionRightToLeft, notificationData.direct ion);
88 EXPECT_EQ(kNotificationLang, notificationData.lang); 91 EXPECT_EQ(kNotificationLang, notificationData.lang);
89 EXPECT_EQ(kNotificationBody, notificationData.body); 92 EXPECT_EQ(kNotificationBody, notificationData.body);
90 EXPECT_EQ(kNotificationTag, notificationData.tag); 93 EXPECT_EQ(kNotificationTag, notificationData.tag);
91 94
92 // TODO(peter): Test notificationData.icon when ExecutionContext::completeUR L() works in this test. 95 // TODO(peter): Test notificationData.icon when ExecutionContext::completeUR L() works in this test.
93 96
94 ASSERT_EQ(vibrationPattern.size(), notificationData.vibrate.size()); 97 ASSERT_EQ(vibrationPattern.size(), notificationData.vibrate.size());
95 for (size_t i = 0; i < vibrationPattern.size(); ++i) 98 for (size_t i = 0; i < vibrationPattern.size(); ++i)
96 EXPECT_EQ(vibrationPattern[i], static_cast<unsigned>(notificationData.vi brate[i])); 99 EXPECT_EQ(vibrationPattern[i], static_cast<unsigned>(notificationData.vi brate[i]));
97 100
101 EXPECT_EQ(kNotificationTimestamp, notificationData.timestamp);
98 EXPECT_EQ(kNotificationSilent, notificationData.silent); 102 EXPECT_EQ(kNotificationSilent, notificationData.silent);
99 EXPECT_EQ(kNotificationRequireInteraction, notificationData.requireInteracti on); 103 EXPECT_EQ(kNotificationRequireInteraction, notificationData.requireInteracti on);
100 EXPECT_EQ(actions.size(), notificationData.actions.size()); 104 EXPECT_EQ(actions.size(), notificationData.actions.size());
101 } 105 }
102 106
103 TEST_F(NotificationDataTest, SilentNotificationWithVibration) 107 TEST_F(NotificationDataTest, SilentNotificationWithVibration)
104 { 108 {
105 Vector<unsigned> vibrationPattern; 109 Vector<unsigned> vibrationPattern;
106 for (size_t i = 0; i < arraysize(kNotificationVibration); ++i) 110 for (size_t i = 0; i < arraysize(kNotificationVibration); ++i)
107 vibrationPattern.append(kNotificationVibration[i]); 111 vibrationPattern.append(kNotificationVibration[i]);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 154
151 Vector<int> normalizedPattern; 155 Vector<int> normalizedPattern;
152 for (size_t i = 0; i < arraysize(kNotificationVibrationNormalized); ++i) 156 for (size_t i = 0; i < arraysize(kNotificationVibrationNormalized); ++i)
153 normalizedPattern.append(kNotificationVibrationNormalized[i]); 157 normalizedPattern.append(kNotificationVibrationNormalized[i]);
154 158
155 ASSERT_EQ(normalizedPattern.size(), notificationData.vibrate.size()); 159 ASSERT_EQ(normalizedPattern.size(), notificationData.vibrate.size());
156 for (size_t i = 0; i < normalizedPattern.size(); ++i) 160 for (size_t i = 0; i < normalizedPattern.size(); ++i)
157 EXPECT_EQ(normalizedPattern[i], notificationData.vibrate[i]); 161 EXPECT_EQ(normalizedPattern[i], notificationData.vibrate[i]);
158 } 162 }
159 163
164 TEST_F(NotificationDataTest, DefaultTimestampValue)
165 {
166 NotificationOptions options;
167
168 TrackExceptionState exceptionState;
169 WebNotificationData notificationData = createWebNotificationData(executionCo ntext(), kNotificationTitle, options, exceptionState);
170 EXPECT_FALSE(exceptionState.hadException());
171
172 // The timestamp should be set to the current time since the epoch if it was n't supplied by the developer.
173 // "16" has no significance, but an equal comparison of the value could lead to flaky failures.
174 EXPECT_NEAR(notificationData.timestamp, WTF::currentTimeMS(), 16);
175 }
176
160 TEST_F(NotificationDataTest, DirectionValues) 177 TEST_F(NotificationDataTest, DirectionValues)
161 { 178 {
162 WTF::HashMap<String, WebNotificationData::Direction> mappings; 179 WTF::HashMap<String, WebNotificationData::Direction> mappings;
163 mappings.add("ltr", WebNotificationData::DirectionLeftToRight); 180 mappings.add("ltr", WebNotificationData::DirectionLeftToRight);
164 mappings.add("rtl", WebNotificationData::DirectionRightToLeft); 181 mappings.add("rtl", WebNotificationData::DirectionRightToLeft);
165 mappings.add("auto", WebNotificationData::DirectionAuto); 182 mappings.add("auto", WebNotificationData::DirectionAuto);
166 183
167 // Invalid values should default to "auto". 184 // Invalid values should default to "auto".
168 mappings.add("peter", WebNotificationData::DirectionAuto); 185 mappings.add("peter", WebNotificationData::DirectionAuto);
169 186
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 ASSERT_EQ(Notification::maxActions(), notificationData.actions.size()); 255 ASSERT_EQ(Notification::maxActions(), notificationData.actions.size());
239 256
240 for (size_t i = 0; i < Notification::maxActions(); ++i) { 257 for (size_t i = 0; i < Notification::maxActions(); ++i) {
241 WebString expectedAction = String::number(i); 258 WebString expectedAction = String::number(i);
242 EXPECT_EQ(expectedAction, notificationData.actions[i].action); 259 EXPECT_EQ(expectedAction, notificationData.actions[i].action);
243 } 260 }
244 } 261 }
245 262
246 } // namespace 263 } // namespace
247 } // namespace blink 264 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698