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

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

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

Powered by Google App Engine
This is Rietveld 408576698