Android: Store language .pak files in res/raw rather than assets
[chromium-blink-merge.git] / content / browser / notifications / notification_database_data_unittest.cc
blob2613108db5c4d0030237b569c11e99beae0f2320
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/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace content {
14 const int64_t kNotificationId = 42;
15 const int64_t kServiceWorkerRegistrationId = 9001;
17 const char kOrigin[] = "https://example.com/";
18 const char kNotificationTitle[] = "My Notification";
19 const char kNotificationLang[] = "nl";
20 const char kNotificationBody[] = "Hello, world!";
21 const char kNotificationTag[] = "my_tag";
22 const char kNotificationIconUrl[] = "https://example.com/icon.png";
23 const int kNotificationVibrationPattern[] = { 100, 200, 300 };
24 const unsigned char kNotificationData[] = { 0xdf, 0xff, 0x0, 0x0, 0xff, 0xdf };
26 TEST(NotificationDatabaseDataTest, SerializeAndDeserializeData) {
27 std::vector<int> vibration_pattern(
28 kNotificationVibrationPattern,
29 kNotificationVibrationPattern + arraysize(kNotificationVibrationPattern));
31 std::vector<char> developer_data(
32 kNotificationData, kNotificationData + arraysize(kNotificationData));
34 PlatformNotificationData notification_data;
35 notification_data.title = base::ASCIIToUTF16(kNotificationTitle);
36 notification_data.direction =
37 PlatformNotificationData::NotificationDirectionRightToLeft;
38 notification_data.lang = kNotificationLang;
39 notification_data.body = base::ASCIIToUTF16(kNotificationBody);
40 notification_data.tag = kNotificationTag;
41 notification_data.icon = GURL(kNotificationIconUrl);
42 notification_data.vibration_pattern = vibration_pattern;
43 notification_data.silent = true;
44 notification_data.data = developer_data;
46 NotificationDatabaseData database_data;
47 database_data.notification_id = kNotificationId;
48 database_data.origin = GURL(kOrigin);
49 database_data.service_worker_registration_id = kServiceWorkerRegistrationId;
50 database_data.notification_data = notification_data;
52 std::string serialized_data;
54 // Serialize the data in |notification_data| to the string |serialized_data|.
55 ASSERT_TRUE(SerializeNotificationDatabaseData(database_data,
56 &serialized_data));
58 NotificationDatabaseData copied_data;
60 // Deserialize the data in |serialized_data| to |copied_data|.
61 ASSERT_TRUE(DeserializeNotificationDatabaseData(serialized_data,
62 &copied_data));
64 EXPECT_EQ(database_data.notification_id, copied_data.notification_id);
65 EXPECT_EQ(database_data.origin, copied_data.origin);
66 EXPECT_EQ(database_data.service_worker_registration_id,
67 copied_data.service_worker_registration_id);
69 const PlatformNotificationData& copied_notification_data =
70 copied_data.notification_data;
72 EXPECT_EQ(notification_data.title, copied_notification_data.title);
73 EXPECT_EQ(notification_data.direction, copied_notification_data.direction);
74 EXPECT_EQ(notification_data.lang, copied_notification_data.lang);
75 EXPECT_EQ(notification_data.body, copied_notification_data.body);
76 EXPECT_EQ(notification_data.tag, copied_notification_data.tag);
77 EXPECT_EQ(notification_data.icon, copied_notification_data.icon);
79 EXPECT_THAT(copied_notification_data.vibration_pattern,
80 testing::ElementsAreArray(kNotificationVibrationPattern));
82 EXPECT_EQ(notification_data.silent, copied_notification_data.silent);
84 ASSERT_EQ(developer_data.size(), copied_notification_data.data.size());
85 for (size_t i = 0; i < developer_data.size(); ++i)
86 EXPECT_EQ(developer_data[i], copied_notification_data.data[i]);
89 } // namespace content