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

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

Issue 1750083004: Add badge to web notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test. Created 4 years, 9 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 kNotificationBadgeUrl[] = "https://example.com/badge.png";
30 const char kNotificationActionIconUrl[] = "https://example.com/action_icon.png"; 31 const char kNotificationActionIconUrl[] = "https://example.com/action_icon.png";
31 const int kNotificationVibrationPattern[] = {100, 200, 300}; 32 const int kNotificationVibrationPattern[] = {100, 200, 300};
32 const double kNotificationTimestamp = 621046800.; 33 const double kNotificationTimestamp = 621046800.;
33 const unsigned char kNotificationData[] = {0xdf, 0xff, 0x0, 0x0, 0xff, 0xdf}; 34 const unsigned char kNotificationData[] = {0xdf, 0xff, 0x0, 0x0, 0xff, 0xdf};
34 35
35 TEST(NotificationDatabaseDataTest, SerializeAndDeserializeData) { 36 TEST(NotificationDatabaseDataTest, SerializeAndDeserializeData) {
36 std::vector<int> vibration_pattern( 37 std::vector<int> vibration_pattern(
37 kNotificationVibrationPattern, 38 kNotificationVibrationPattern,
38 kNotificationVibrationPattern + arraysize(kNotificationVibrationPattern)); 39 kNotificationVibrationPattern + arraysize(kNotificationVibrationPattern));
39 40
40 std::vector<char> developer_data( 41 std::vector<char> developer_data(
41 kNotificationData, kNotificationData + arraysize(kNotificationData)); 42 kNotificationData, kNotificationData + arraysize(kNotificationData));
42 43
43 PlatformNotificationData notification_data; 44 PlatformNotificationData notification_data;
44 notification_data.title = base::ASCIIToUTF16(kNotificationTitle); 45 notification_data.title = base::ASCIIToUTF16(kNotificationTitle);
45 notification_data.direction = 46 notification_data.direction =
46 PlatformNotificationData::DIRECTION_RIGHT_TO_LEFT; 47 PlatformNotificationData::DIRECTION_RIGHT_TO_LEFT;
47 notification_data.lang = kNotificationLang; 48 notification_data.lang = kNotificationLang;
48 notification_data.body = base::ASCIIToUTF16(kNotificationBody); 49 notification_data.body = base::ASCIIToUTF16(kNotificationBody);
49 notification_data.tag = kNotificationTag; 50 notification_data.tag = kNotificationTag;
50 notification_data.icon = GURL(kNotificationIconUrl); 51 notification_data.icon = GURL(kNotificationIconUrl);
52 notification_data.badge = GURL(kNotificationBadgeUrl);
51 notification_data.vibration_pattern = vibration_pattern; 53 notification_data.vibration_pattern = vibration_pattern;
52 notification_data.timestamp = base::Time::FromJsTime(kNotificationTimestamp); 54 notification_data.timestamp = base::Time::FromJsTime(kNotificationTimestamp);
53 notification_data.renotify = true; 55 notification_data.renotify = true;
54 notification_data.silent = true; 56 notification_data.silent = true;
55 notification_data.require_interaction = true; 57 notification_data.require_interaction = true;
56 notification_data.data = developer_data; 58 notification_data.data = developer_data;
57 for (size_t i = 0; i < kPlatformNotificationMaxActions; i++) { 59 for (size_t i = 0; i < kPlatformNotificationMaxActions; i++) {
58 PlatformNotificationAction notification_action; 60 PlatformNotificationAction notification_action;
59 notification_action.action = base::SizeTToString(i); 61 notification_action.action = base::SizeTToString(i);
60 notification_action.title = base::SizeTToString16(i); 62 notification_action.title = base::SizeTToString16(i);
(...skipping 26 matching lines...) Expand all
87 89
88 const PlatformNotificationData& copied_notification_data = 90 const PlatformNotificationData& copied_notification_data =
89 copied_data.notification_data; 91 copied_data.notification_data;
90 92
91 EXPECT_EQ(notification_data.title, copied_notification_data.title); 93 EXPECT_EQ(notification_data.title, copied_notification_data.title);
92 EXPECT_EQ(notification_data.direction, copied_notification_data.direction); 94 EXPECT_EQ(notification_data.direction, copied_notification_data.direction);
93 EXPECT_EQ(notification_data.lang, copied_notification_data.lang); 95 EXPECT_EQ(notification_data.lang, copied_notification_data.lang);
94 EXPECT_EQ(notification_data.body, copied_notification_data.body); 96 EXPECT_EQ(notification_data.body, copied_notification_data.body);
95 EXPECT_EQ(notification_data.tag, copied_notification_data.tag); 97 EXPECT_EQ(notification_data.tag, copied_notification_data.tag);
96 EXPECT_EQ(notification_data.icon, copied_notification_data.icon); 98 EXPECT_EQ(notification_data.icon, copied_notification_data.icon);
99 EXPECT_EQ(notification_data.badge, copied_notification_data.badge);
97 100
98 EXPECT_THAT(copied_notification_data.vibration_pattern, 101 EXPECT_THAT(copied_notification_data.vibration_pattern,
99 testing::ElementsAreArray(kNotificationVibrationPattern)); 102 testing::ElementsAreArray(kNotificationVibrationPattern));
100 103
101 EXPECT_EQ(notification_data.timestamp, copied_notification_data.timestamp); 104 EXPECT_EQ(notification_data.timestamp, copied_notification_data.timestamp);
102 EXPECT_EQ(notification_data.renotify, copied_notification_data.renotify); 105 EXPECT_EQ(notification_data.renotify, copied_notification_data.renotify);
103 EXPECT_EQ(notification_data.silent, copied_notification_data.silent); 106 EXPECT_EQ(notification_data.silent, copied_notification_data.silent);
104 EXPECT_EQ(notification_data.require_interaction, 107 EXPECT_EQ(notification_data.require_interaction,
105 copied_notification_data.require_interaction); 108 copied_notification_data.require_interaction);
106 109
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 142
140 NotificationDatabaseData copied_data; 143 NotificationDatabaseData copied_data;
141 ASSERT_TRUE( 144 ASSERT_TRUE(
142 DeserializeNotificationDatabaseData(serialized_data, &copied_data)); 145 DeserializeNotificationDatabaseData(serialized_data, &copied_data));
143 146
144 EXPECT_EQ(directions[i], copied_data.notification_data.direction); 147 EXPECT_EQ(directions[i], copied_data.notification_data.direction);
145 } 148 }
146 } 149 }
147 150
148 } // namespace content 151 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698