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
3 // found in the LICENSE file.
5 #include "base/strings/utf_string_conversions.h"
6 #include "content/browser/notifications/notification_database_data.pb.h"
7 #include "content/browser/notifications/notification_database_data_conversions.h"
8 #include "content/public/browser/notification_database_data.h"
9 #include "testing/gtest/include/gtest/gtest.h"
13 const int64_t kNotificationId
= 42;
14 const int64_t kServiceWorkerRegistrationId
= 9001;
16 const char kOrigin
[] = "https://example.com/";
17 const char kNotificationTitle
[] = "My Notification";
18 const char kNotificationLang
[] = "nl";
19 const char kNotificationBody
[] = "Hello, world!";
20 const char kNotificationTag
[] = "my_tag";
21 const char kNotificationIconUrl
[] = "https://example.com/icon.png";
23 TEST(NotificationDatabaseDataTest
, SerializeAndDeserializeData
) {
24 PlatformNotificationData notification_data
;
25 notification_data
.title
= base::ASCIIToUTF16(kNotificationTitle
);
26 notification_data
.direction
=
27 PlatformNotificationData::NotificationDirectionRightToLeft
;
28 notification_data
.lang
= kNotificationLang
;
29 notification_data
.body
= base::ASCIIToUTF16(kNotificationBody
);
30 notification_data
.tag
= kNotificationTag
;
31 notification_data
.icon
= GURL(kNotificationIconUrl
);
32 notification_data
.silent
= true;
34 NotificationDatabaseData database_data
;
35 database_data
.notification_id
= kNotificationId
;
36 database_data
.origin
= GURL(kOrigin
);
37 database_data
.service_worker_registration_id
= kServiceWorkerRegistrationId
;
38 database_data
.notification_data
= notification_data
;
40 std::string serialized_data
;
42 // Serialize the data in |notification_data| to the string |serialized_data|.
43 ASSERT_TRUE(SerializeNotificationDatabaseData(database_data
,
46 NotificationDatabaseData copied_data
;
48 // Deserialize the data in |serialized_data| to |copied_data|.
49 ASSERT_TRUE(DeserializeNotificationDatabaseData(serialized_data
,
52 EXPECT_EQ(database_data
.notification_id
, copied_data
.notification_id
);
53 EXPECT_EQ(database_data
.origin
, copied_data
.origin
);
54 EXPECT_EQ(database_data
.service_worker_registration_id
,
55 copied_data
.service_worker_registration_id
);
57 const PlatformNotificationData
& copied_notification_data
=
58 copied_data
.notification_data
;
60 EXPECT_EQ(notification_data
.title
, copied_notification_data
.title
);
61 EXPECT_EQ(notification_data
.direction
, copied_notification_data
.direction
);
62 EXPECT_EQ(notification_data
.lang
, copied_notification_data
.lang
);
63 EXPECT_EQ(notification_data
.body
, copied_notification_data
.body
);
64 EXPECT_EQ(notification_data
.tag
, copied_notification_data
.tag
);
65 EXPECT_EQ(notification_data
.icon
, copied_notification_data
.icon
);
66 EXPECT_EQ(notification_data
.silent
, copied_notification_data
.silent
);
69 } // namespace content