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

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

Issue 1003843002: Add the NotificationDatabaseData structure and protobuf (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-db-GetNextNotificationId
Patch Set: remove the anonymous namespace Created 5 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
(Empty)
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.
4
5 #include "content/browser/notifications/notification_database_data.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "content/browser/notifications/notification_database_data.pb.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace content {
12
13 const int64_t kNotificationId = 42;
14 const int64_t kServiceWorkerRegistrationId = 9001;
15
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";
22
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;
33
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;
39
40 std::string serialized_data;
41
42 // Serialize the data in |notification_data| to the string |serialized_data|.
43 ASSERT_TRUE(database_data.SerializeToString(&serialized_data));
44
45 NotificationDatabaseData copied_data;
46
47 // Deserialize the data in |serialized_data| to |copied_data|.
48 ASSERT_TRUE(copied_data.ParseFromString(serialized_data));
49
50 EXPECT_EQ(database_data.notification_id, copied_data.notification_id);
51 EXPECT_EQ(database_data.origin, copied_data.origin);
52 EXPECT_EQ(database_data.service_worker_registration_id,
53 copied_data.service_worker_registration_id);
54
55 const PlatformNotificationData& copied_notification_data =
56 copied_data.notification_data;
57
58 EXPECT_EQ(notification_data.title, copied_notification_data.title);
59 EXPECT_EQ(notification_data.direction, copied_notification_data.direction);
60 EXPECT_EQ(notification_data.lang, copied_notification_data.lang);
61 EXPECT_EQ(notification_data.body, copied_notification_data.body);
62 EXPECT_EQ(notification_data.tag, copied_notification_data.tag);
63 EXPECT_EQ(notification_data.icon, copied_notification_data.icon);
64 EXPECT_EQ(notification_data.silent, copied_notification_data.silent);
65 }
66
67 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/notifications/notification_database_data.proto ('k') | content/browser/notifications/notification_proto.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698