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

Side by Side Diff: content/browser/notifications/notification_database_data_unittest.cc

Issue 1388483002: Implement the Notification `timestamp` property (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/time/time.h"
11 #include "content/browser/notifications/notification_database_data.pb.h" 12 #include "content/browser/notifications/notification_database_data.pb.h"
12 #include "content/browser/notifications/notification_database_data_conversions.h " 13 #include "content/browser/notifications/notification_database_data_conversions.h "
13 #include "content/common/notification_constants.h" 14 #include "content/common/notification_constants.h"
14 #include "content/public/browser/notification_database_data.h" 15 #include "content/public/browser/notification_database_data.h"
15 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 namespace content { 19 namespace content {
19 20
20 const int64_t kNotificationId = 42; 21 const int64_t kNotificationId = 42;
21 const int64_t kServiceWorkerRegistrationId = 9001; 22 const int64_t kServiceWorkerRegistrationId = 9001;
22 23
23 const char kOrigin[] = "https://example.com/"; 24 const char kOrigin[] = "https://example.com/";
24 const char kNotificationTitle[] = "My Notification"; 25 const char kNotificationTitle[] = "My Notification";
25 const char kNotificationLang[] = "nl"; 26 const char kNotificationLang[] = "nl";
26 const char kNotificationBody[] = "Hello, world!"; 27 const char kNotificationBody[] = "Hello, world!";
27 const char kNotificationTag[] = "my_tag"; 28 const char kNotificationTag[] = "my_tag";
28 const char kNotificationIconUrl[] = "https://example.com/icon.png"; 29 const char kNotificationIconUrl[] = "https://example.com/icon.png";
29 const int kNotificationVibrationPattern[] = {100, 200, 300}; 30 const int kNotificationVibrationPattern[] = {100, 200, 300};
31 const double kNotificationTimestamp = 621046800.;
30 const unsigned char kNotificationData[] = {0xdf, 0xff, 0x0, 0x0, 0xff, 0xdf}; 32 const unsigned char kNotificationData[] = {0xdf, 0xff, 0x0, 0x0, 0xff, 0xdf};
31 33
32 TEST(NotificationDatabaseDataTest, SerializeAndDeserializeData) { 34 TEST(NotificationDatabaseDataTest, SerializeAndDeserializeData) {
33 std::vector<int> vibration_pattern( 35 std::vector<int> vibration_pattern(
34 kNotificationVibrationPattern, 36 kNotificationVibrationPattern,
35 kNotificationVibrationPattern + arraysize(kNotificationVibrationPattern)); 37 kNotificationVibrationPattern + arraysize(kNotificationVibrationPattern));
36 38
37 std::vector<char> developer_data( 39 std::vector<char> developer_data(
38 kNotificationData, kNotificationData + arraysize(kNotificationData)); 40 kNotificationData, kNotificationData + arraysize(kNotificationData));
39 41
40 PlatformNotificationData notification_data; 42 PlatformNotificationData notification_data;
41 notification_data.title = base::ASCIIToUTF16(kNotificationTitle); 43 notification_data.title = base::ASCIIToUTF16(kNotificationTitle);
42 notification_data.direction = 44 notification_data.direction =
43 PlatformNotificationData::DIRECTION_RIGHT_TO_LEFT; 45 PlatformNotificationData::DIRECTION_RIGHT_TO_LEFT;
44 notification_data.lang = kNotificationLang; 46 notification_data.lang = kNotificationLang;
45 notification_data.body = base::ASCIIToUTF16(kNotificationBody); 47 notification_data.body = base::ASCIIToUTF16(kNotificationBody);
46 notification_data.tag = kNotificationTag; 48 notification_data.tag = kNotificationTag;
47 notification_data.icon = GURL(kNotificationIconUrl); 49 notification_data.icon = GURL(kNotificationIconUrl);
48 notification_data.vibration_pattern = vibration_pattern; 50 notification_data.vibration_pattern = vibration_pattern;
51 notification_data.timestamp = base::Time::FromJsTime(kNotificationTimestamp);
49 notification_data.silent = true; 52 notification_data.silent = true;
50 notification_data.require_interaction = true; 53 notification_data.require_interaction = true;
51 notification_data.data = developer_data; 54 notification_data.data = developer_data;
52 for (size_t i = 0; i < kPlatformNotificationMaxActions; i++) { 55 for (size_t i = 0; i < kPlatformNotificationMaxActions; i++) {
53 PlatformNotificationAction notification_action; 56 PlatformNotificationAction notification_action;
54 notification_action.action = base::SizeTToString(i); 57 notification_action.action = base::SizeTToString(i);
55 notification_action.title = base::SizeTToString16(i); 58 notification_action.title = base::SizeTToString16(i);
56 notification_data.actions.push_back(notification_action); 59 notification_data.actions.push_back(notification_action);
57 } 60 }
58 61
(...skipping 26 matching lines...) Expand all
85 EXPECT_EQ(notification_data.title, copied_notification_data.title); 88 EXPECT_EQ(notification_data.title, copied_notification_data.title);
86 EXPECT_EQ(notification_data.direction, copied_notification_data.direction); 89 EXPECT_EQ(notification_data.direction, copied_notification_data.direction);
87 EXPECT_EQ(notification_data.lang, copied_notification_data.lang); 90 EXPECT_EQ(notification_data.lang, copied_notification_data.lang);
88 EXPECT_EQ(notification_data.body, copied_notification_data.body); 91 EXPECT_EQ(notification_data.body, copied_notification_data.body);
89 EXPECT_EQ(notification_data.tag, copied_notification_data.tag); 92 EXPECT_EQ(notification_data.tag, copied_notification_data.tag);
90 EXPECT_EQ(notification_data.icon, copied_notification_data.icon); 93 EXPECT_EQ(notification_data.icon, copied_notification_data.icon);
91 94
92 EXPECT_THAT(copied_notification_data.vibration_pattern, 95 EXPECT_THAT(copied_notification_data.vibration_pattern,
93 testing::ElementsAreArray(kNotificationVibrationPattern)); 96 testing::ElementsAreArray(kNotificationVibrationPattern));
94 97
98 EXPECT_EQ(notification_data.timestamp, copied_notification_data.timestamp);
95 EXPECT_EQ(notification_data.silent, copied_notification_data.silent); 99 EXPECT_EQ(notification_data.silent, copied_notification_data.silent);
96 EXPECT_EQ(notification_data.require_interaction, 100 EXPECT_EQ(notification_data.require_interaction,
97 copied_notification_data.require_interaction); 101 copied_notification_data.require_interaction);
98 102
99 ASSERT_EQ(developer_data.size(), copied_notification_data.data.size()); 103 ASSERT_EQ(developer_data.size(), copied_notification_data.data.size());
100 for (size_t i = 0; i < developer_data.size(); ++i) 104 for (size_t i = 0; i < developer_data.size(); ++i)
101 EXPECT_EQ(developer_data[i], copied_notification_data.data[i]); 105 EXPECT_EQ(developer_data[i], copied_notification_data.data[i]);
102 106
103 ASSERT_EQ(notification_data.actions.size(), 107 ASSERT_EQ(notification_data.actions.size(),
104 copied_notification_data.actions.size()); 108 copied_notification_data.actions.size());
(...skipping 24 matching lines...) Expand all
129 133
130 NotificationDatabaseData copied_data; 134 NotificationDatabaseData copied_data;
131 ASSERT_TRUE( 135 ASSERT_TRUE(
132 DeserializeNotificationDatabaseData(serialized_data, &copied_data)); 136 DeserializeNotificationDatabaseData(serialized_data, &copied_data));
133 137
134 EXPECT_EQ(directions[i], copied_data.notification_data.direction); 138 EXPECT_EQ(directions[i], copied_data.notification_data.direction);
135 } 139 }
136 } 140 }
137 141
138 } // namespace content 142 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698