Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / child / notifications / notification_data_conversions_unittest.cc
blobdaded25dfd5f8eede6b29226cf70e7eb170b7e02
1 // Copyright 2014 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 "content/child/notifications/notification_data_conversions.h"
7 #include <stdint.h>
9 #include "base/strings/utf_string_conversions.h"
10 #include "content/public/common/platform_notification_data.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/WebKit/public/platform/WebString.h"
13 #include "third_party/WebKit/public/platform/WebURL.h"
14 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificationData.h"
16 namespace content {
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 unsigned char kNotificationData[] = { 0xdf, 0xff, 0x0, 0x0, 0xff, 0xdf };
25 TEST(NotificationDataConversionsTest, ToPlatformNotificationData) {
26 std::vector<char> developer_data(
27 kNotificationData, kNotificationData + arraysize(kNotificationData));
29 blink::WebNotificationData web_data(
30 blink::WebString::fromUTF8(kNotificationTitle),
31 blink::WebNotificationData::DirectionLeftToRight,
32 blink::WebString::fromUTF8(kNotificationLang),
33 blink::WebString::fromUTF8(kNotificationBody),
34 blink::WebString::fromUTF8(kNotificationTag),
35 blink::WebURL(GURL(kNotificationIconUrl)),
36 true /* silent */,
37 blink::WebVector<char>(developer_data));
39 PlatformNotificationData platform_data = ToPlatformNotificationData(web_data);
40 EXPECT_EQ(base::ASCIIToUTF16(kNotificationTitle), platform_data.title);
41 EXPECT_EQ(PlatformNotificationData::NotificationDirectionLeftToRight,
42 platform_data.direction);
43 EXPECT_EQ(kNotificationLang, platform_data.lang);
44 EXPECT_EQ(base::ASCIIToUTF16(kNotificationBody), platform_data.body);
45 EXPECT_EQ(kNotificationTag, platform_data.tag);
46 EXPECT_EQ(kNotificationIconUrl, platform_data.icon.spec());
47 EXPECT_TRUE(platform_data.silent);
49 ASSERT_EQ(developer_data.size(), platform_data.data.size());
50 for (size_t i = 0; i < developer_data.size(); ++i)
51 EXPECT_EQ(developer_data[i], platform_data.data[i]);
54 TEST(NotificationDataConversionsTest,
55 ToPlatformNotificationDataDirectionality) {
56 blink::WebNotificationData web_data;
57 web_data.direction = blink::WebNotificationData::DirectionLeftToRight;
59 PlatformNotificationData platform_data = ToPlatformNotificationData(web_data);
60 EXPECT_EQ(PlatformNotificationData::NotificationDirectionLeftToRight,
61 platform_data.direction);
63 web_data.direction = blink::WebNotificationData::DirectionRightToLeft;
65 platform_data = ToPlatformNotificationData(web_data);
66 EXPECT_EQ(PlatformNotificationData::NotificationDirectionRightToLeft,
67 platform_data.direction);
70 TEST(NotificationDataConversionsTest, ToWebNotificationData) {
71 std::vector<char> developer_data(
72 kNotificationData, kNotificationData + arraysize(kNotificationData));
74 PlatformNotificationData platform_data;
75 platform_data.title = base::ASCIIToUTF16(kNotificationTitle);
76 platform_data.direction =
77 PlatformNotificationData::NotificationDirectionLeftToRight;
78 platform_data.lang = kNotificationLang;
79 platform_data.body = base::ASCIIToUTF16(kNotificationBody);
80 platform_data.tag = kNotificationTag;
81 platform_data.icon = GURL(kNotificationIconUrl);
82 platform_data.silent = true;
83 platform_data.data = developer_data;
85 blink::WebNotificationData web_data = ToWebNotificationData(platform_data);
86 EXPECT_EQ(kNotificationTitle, web_data.title);
87 EXPECT_EQ(blink::WebNotificationData::DirectionLeftToRight,
88 web_data.direction);
89 EXPECT_EQ(kNotificationLang, web_data.lang);
90 EXPECT_EQ(kNotificationBody, web_data.body);
91 EXPECT_EQ(kNotificationTag, web_data.tag);
92 EXPECT_EQ(kNotificationIconUrl, web_data.icon.string());
93 EXPECT_TRUE(web_data.silent);
95 ASSERT_EQ(developer_data.size(), web_data.data.size());
96 for (size_t i = 0; i < developer_data.size(); ++i)
97 EXPECT_EQ(developer_data[i], web_data.data[i]);
100 TEST(NotificationDataConversionsTest, ToWebNotificationDataDirectionality) {
101 PlatformNotificationData platform_data;
102 platform_data.direction =
103 PlatformNotificationData::NotificationDirectionLeftToRight;
105 blink::WebNotificationData web_data = ToWebNotificationData(platform_data);
106 EXPECT_EQ(blink::WebNotificationData::DirectionLeftToRight,
107 web_data.direction);
109 platform_data.direction =
110 PlatformNotificationData::NotificationDirectionRightToLeft;
112 web_data = ToWebNotificationData(platform_data);
113 EXPECT_EQ(blink::WebNotificationData::DirectionRightToLeft,
114 web_data.direction);
117 } // namespace content