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 <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 "content/browser/notifications/notification_database_data.pb.h" | 11 #include "content/browser/notifications/notification_database_data.pb.h" |
12 #include "content/browser/notifications/notification_database_data_conversions.h
" | 12 #include "content/browser/notifications/notification_database_data_conversions.h
" |
13 #include "content/common/notification_constants.h" | 13 #include "content/common/notification_constants.h" |
14 #include "content/public/browser/notification_database_data.h" | 14 #include "content/public/browser/notification_database_data.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
20 const int64_t kNotificationId = 42; | 20 const int64_t kNotificationId = 42; |
21 const int64_t kServiceWorkerRegistrationId = 9001; | 21 const int64_t kServiceWorkerRegistrationId = 9001; |
22 | 22 |
23 const char kOrigin[] = "https://example.com/"; | 23 const char kOrigin[] = "https://example.com/"; |
24 const char kNotificationTitle[] = "My Notification"; | 24 const char kNotificationTitle[] = "My Notification"; |
25 const char kNotificationLang[] = "nl"; | 25 const char kNotificationLang[] = "nl"; |
26 const char kNotificationBody[] = "Hello, world!"; | 26 const char kNotificationBody[] = "Hello, world!"; |
27 const char kNotificationTag[] = "my_tag"; | 27 const char kNotificationTag[] = "my_tag"; |
28 const char kNotificationIconUrl[] = "https://example.com/icon.png"; | 28 const char kNotificationIconUrl[] = "https://example.com/icon.png"; |
| 29 const char kNotificationActionIconUrl[] = "https://example.com/action_icon.png"; |
29 const int kNotificationVibrationPattern[] = {100, 200, 300}; | 30 const int kNotificationVibrationPattern[] = {100, 200, 300}; |
30 const unsigned char kNotificationData[] = {0xdf, 0xff, 0x0, 0x0, 0xff, 0xdf}; | 31 const unsigned char kNotificationData[] = {0xdf, 0xff, 0x0, 0x0, 0xff, 0xdf}; |
31 | 32 |
32 TEST(NotificationDatabaseDataTest, SerializeAndDeserializeData) { | 33 TEST(NotificationDatabaseDataTest, SerializeAndDeserializeData) { |
33 std::vector<int> vibration_pattern( | 34 std::vector<int> vibration_pattern( |
34 kNotificationVibrationPattern, | 35 kNotificationVibrationPattern, |
35 kNotificationVibrationPattern + arraysize(kNotificationVibrationPattern)); | 36 kNotificationVibrationPattern + arraysize(kNotificationVibrationPattern)); |
36 | 37 |
37 std::vector<char> developer_data( | 38 std::vector<char> developer_data( |
38 kNotificationData, kNotificationData + arraysize(kNotificationData)); | 39 kNotificationData, kNotificationData + arraysize(kNotificationData)); |
39 | 40 |
40 PlatformNotificationData notification_data; | 41 PlatformNotificationData notification_data; |
41 notification_data.title = base::ASCIIToUTF16(kNotificationTitle); | 42 notification_data.title = base::ASCIIToUTF16(kNotificationTitle); |
42 notification_data.direction = | 43 notification_data.direction = |
43 PlatformNotificationData::DIRECTION_RIGHT_TO_LEFT; | 44 PlatformNotificationData::DIRECTION_RIGHT_TO_LEFT; |
44 notification_data.lang = kNotificationLang; | 45 notification_data.lang = kNotificationLang; |
45 notification_data.body = base::ASCIIToUTF16(kNotificationBody); | 46 notification_data.body = base::ASCIIToUTF16(kNotificationBody); |
46 notification_data.tag = kNotificationTag; | 47 notification_data.tag = kNotificationTag; |
47 notification_data.icon = GURL(kNotificationIconUrl); | 48 notification_data.icon = GURL(kNotificationIconUrl); |
48 notification_data.vibration_pattern = vibration_pattern; | 49 notification_data.vibration_pattern = vibration_pattern; |
49 notification_data.silent = true; | 50 notification_data.silent = true; |
50 notification_data.require_interaction = true; | 51 notification_data.require_interaction = true; |
51 notification_data.data = developer_data; | 52 notification_data.data = developer_data; |
52 for (size_t i = 0; i < kPlatformNotificationMaxActions; i++) { | 53 for (size_t i = 0; i < kPlatformNotificationMaxActions; i++) { |
53 PlatformNotificationAction notification_action; | 54 PlatformNotificationAction notification_action; |
54 notification_action.action = base::SizeTToString(i); | 55 notification_action.action = base::SizeTToString(i); |
55 notification_action.title = base::SizeTToString16(i); | 56 notification_action.title = base::SizeTToString16(i); |
| 57 notification_action.icon = GURL(kNotificationActionIconUrl); |
56 notification_data.actions.push_back(notification_action); | 58 notification_data.actions.push_back(notification_action); |
57 } | 59 } |
58 | 60 |
59 NotificationDatabaseData database_data; | 61 NotificationDatabaseData database_data; |
60 database_data.notification_id = kNotificationId; | 62 database_data.notification_id = kNotificationId; |
61 database_data.origin = GURL(kOrigin); | 63 database_data.origin = GURL(kOrigin); |
62 database_data.service_worker_registration_id = kServiceWorkerRegistrationId; | 64 database_data.service_worker_registration_id = kServiceWorkerRegistrationId; |
63 database_data.notification_data = notification_data; | 65 database_data.notification_data = notification_data; |
64 | 66 |
65 std::string serialized_data; | 67 std::string serialized_data; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 for (size_t i = 0; i < developer_data.size(); ++i) | 102 for (size_t i = 0; i < developer_data.size(); ++i) |
101 EXPECT_EQ(developer_data[i], copied_notification_data.data[i]); | 103 EXPECT_EQ(developer_data[i], copied_notification_data.data[i]); |
102 | 104 |
103 ASSERT_EQ(notification_data.actions.size(), | 105 ASSERT_EQ(notification_data.actions.size(), |
104 copied_notification_data.actions.size()); | 106 copied_notification_data.actions.size()); |
105 for (size_t i = 0; i < notification_data.actions.size(); ++i) { | 107 for (size_t i = 0; i < notification_data.actions.size(); ++i) { |
106 EXPECT_EQ(notification_data.actions[i].action, | 108 EXPECT_EQ(notification_data.actions[i].action, |
107 copied_notification_data.actions[i].action); | 109 copied_notification_data.actions[i].action); |
108 EXPECT_EQ(notification_data.actions[i].title, | 110 EXPECT_EQ(notification_data.actions[i].title, |
109 copied_notification_data.actions[i].title); | 111 copied_notification_data.actions[i].title); |
| 112 EXPECT_EQ(notification_data.actions[i].icon, |
| 113 copied_notification_data.actions[i].icon); |
110 } | 114 } |
111 } | 115 } |
112 | 116 |
113 TEST(NotificationDatabaseDataTest, SerializeAndDeserializeDirections) { | 117 TEST(NotificationDatabaseDataTest, SerializeAndDeserializeDirections) { |
114 PlatformNotificationData::Direction directions[] = { | 118 PlatformNotificationData::Direction directions[] = { |
115 PlatformNotificationData::DIRECTION_LEFT_TO_RIGHT, | 119 PlatformNotificationData::DIRECTION_LEFT_TO_RIGHT, |
116 PlatformNotificationData::DIRECTION_RIGHT_TO_LEFT, | 120 PlatformNotificationData::DIRECTION_RIGHT_TO_LEFT, |
117 PlatformNotificationData::DIRECTION_AUTO}; | 121 PlatformNotificationData::DIRECTION_AUTO}; |
118 | 122 |
119 for (size_t i = 0; i < arraysize(directions); ++i) { | 123 for (size_t i = 0; i < arraysize(directions); ++i) { |
120 PlatformNotificationData notification_data; | 124 PlatformNotificationData notification_data; |
121 notification_data.direction = directions[i]; | 125 notification_data.direction = directions[i]; |
122 | 126 |
123 NotificationDatabaseData database_data; | 127 NotificationDatabaseData database_data; |
124 database_data.notification_data = notification_data; | 128 database_data.notification_data = notification_data; |
125 | 129 |
126 std::string serialized_data; | 130 std::string serialized_data; |
127 ASSERT_TRUE( | 131 ASSERT_TRUE( |
128 SerializeNotificationDatabaseData(database_data, &serialized_data)); | 132 SerializeNotificationDatabaseData(database_data, &serialized_data)); |
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 |
OLD | NEW |