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

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

Issue 1262023003: Serialize Notification.direction == "auto" in the database (2/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "content/browser/notifications/notification_database_data.pb.h" 6 #include "content/browser/notifications/notification_database_data.pb.h"
7 #include "content/browser/notifications/notification_database_data_conversions.h " 7 #include "content/browser/notifications/notification_database_data_conversions.h "
8 #include "content/public/browser/notification_database_data.h" 8 #include "content/public/browser/notification_database_data.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 16 matching lines...) Expand all
27 std::vector<int> vibration_pattern( 27 std::vector<int> vibration_pattern(
28 kNotificationVibrationPattern, 28 kNotificationVibrationPattern,
29 kNotificationVibrationPattern + arraysize(kNotificationVibrationPattern)); 29 kNotificationVibrationPattern + arraysize(kNotificationVibrationPattern));
30 30
31 std::vector<char> developer_data( 31 std::vector<char> developer_data(
32 kNotificationData, kNotificationData + arraysize(kNotificationData)); 32 kNotificationData, kNotificationData + arraysize(kNotificationData));
33 33
34 PlatformNotificationData notification_data; 34 PlatformNotificationData notification_data;
35 notification_data.title = base::ASCIIToUTF16(kNotificationTitle); 35 notification_data.title = base::ASCIIToUTF16(kNotificationTitle);
36 notification_data.direction = 36 notification_data.direction =
37 PlatformNotificationData::NotificationDirectionRightToLeft; 37 PlatformNotificationData::DIRECTION_RIGHT_TO_LEFT;
38 notification_data.lang = kNotificationLang; 38 notification_data.lang = kNotificationLang;
39 notification_data.body = base::ASCIIToUTF16(kNotificationBody); 39 notification_data.body = base::ASCIIToUTF16(kNotificationBody);
40 notification_data.tag = kNotificationTag; 40 notification_data.tag = kNotificationTag;
41 notification_data.icon = GURL(kNotificationIconUrl); 41 notification_data.icon = GURL(kNotificationIconUrl);
42 notification_data.vibration_pattern = vibration_pattern; 42 notification_data.vibration_pattern = vibration_pattern;
43 notification_data.silent = true; 43 notification_data.silent = true;
44 notification_data.data = developer_data; 44 notification_data.data = developer_data;
45 45
46 NotificationDatabaseData database_data; 46 NotificationDatabaseData database_data;
47 database_data.notification_id = kNotificationId; 47 database_data.notification_id = kNotificationId;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 EXPECT_THAT(copied_notification_data.vibration_pattern, 79 EXPECT_THAT(copied_notification_data.vibration_pattern,
80 testing::ElementsAreArray(kNotificationVibrationPattern)); 80 testing::ElementsAreArray(kNotificationVibrationPattern));
81 81
82 EXPECT_EQ(notification_data.silent, copied_notification_data.silent); 82 EXPECT_EQ(notification_data.silent, copied_notification_data.silent);
83 83
84 ASSERT_EQ(developer_data.size(), copied_notification_data.data.size()); 84 ASSERT_EQ(developer_data.size(), copied_notification_data.data.size());
85 for (size_t i = 0; i < developer_data.size(); ++i) 85 for (size_t i = 0; i < developer_data.size(); ++i)
86 EXPECT_EQ(developer_data[i], copied_notification_data.data[i]); 86 EXPECT_EQ(developer_data[i], copied_notification_data.data[i]);
87 } 87 }
88 88
89 TEST(NotificationDatabaseDataTest, SerializeAndDeserializeDirections) {
90 PlatformNotificationData::Direction directions[] = {
91 PlatformNotificationData::DIRECTION_LEFT_TO_RIGHT,
92 PlatformNotificationData::DIRECTION_RIGHT_TO_LEFT,
93 PlatformNotificationData::DIRECTION_AUTO
palmer 2015/08/03 20:42:46 Might be good to add a negative test case.
94 };
95
96 for (size_t i = 0; i < arraysize(directions); ++i) {
97 PlatformNotificationData notification_data;
98 notification_data.direction = directions[i];
99
100 NotificationDatabaseData database_data;
101 database_data.notification_data = notification_data;
102
103 std::string serialized_data;
104 ASSERT_TRUE(SerializeNotificationDatabaseData(database_data,
105 &serialized_data));
106
107 NotificationDatabaseData copied_data;
108 ASSERT_TRUE(DeserializeNotificationDatabaseData(serialized_data,
109 &copied_data));
110
111 EXPECT_EQ(directions[i], copied_data.notification_data.direction);
112 }
113 }
114
89 } // namespace content 115 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698