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 "base/strings/utf_string_conversions.h"
8 #include "content/public/common/platform_notification_data.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/WebKit/public/platform/WebString.h"
11 #include "third_party/WebKit/public/platform/WebURL.h"
12 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificationData.h"
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";
25 TEST(NotificationDataConversionsTest
, ToPlatformNotificationData
) {
26 blink::WebNotificationData
web_data(
27 blink::WebString::fromUTF8(kNotificationTitle
),
28 blink::WebNotificationData::DirectionLeftToRight
,
29 blink::WebString::fromUTF8(kNotificationLang
),
30 blink::WebString::fromUTF8(kNotificationBody
),
31 blink::WebString::fromUTF8(kNotificationTag
),
32 blink::WebURL(GURL(kNotificationIconUrl
)),
35 PlatformNotificationData platform_data
= ToPlatformNotificationData(web_data
);
36 EXPECT_EQ(base::ASCIIToUTF16(kNotificationTitle
), platform_data
.title
);
37 EXPECT_EQ(PlatformNotificationData::NotificationDirectionLeftToRight
,
38 platform_data
.direction
);
39 EXPECT_EQ(kNotificationLang
, platform_data
.lang
);
40 EXPECT_EQ(base::ASCIIToUTF16(kNotificationBody
), platform_data
.body
);
41 EXPECT_EQ(kNotificationTag
, platform_data
.tag
);
42 EXPECT_EQ(kNotificationIconUrl
, platform_data
.icon
.spec());
43 EXPECT_TRUE(platform_data
.silent
);
46 TEST(NotificationDataConversionsTest
,
47 ToPlatformNotificationDataDirectionality
) {
48 blink::WebNotificationData web_data
;
49 web_data
.direction
= blink::WebNotificationData::DirectionLeftToRight
;
51 PlatformNotificationData platform_data
= ToPlatformNotificationData(web_data
);
52 EXPECT_EQ(PlatformNotificationData::NotificationDirectionLeftToRight
,
53 platform_data
.direction
);
55 web_data
.direction
= blink::WebNotificationData::DirectionRightToLeft
;
57 platform_data
= ToPlatformNotificationData(web_data
);
58 EXPECT_EQ(PlatformNotificationData::NotificationDirectionRightToLeft
,
59 platform_data
.direction
);
62 TEST(NotificationDataConversionsTest
, ToWebNotificationData
) {
63 PlatformNotificationData platform_data
;
64 platform_data
.title
= base::ASCIIToUTF16(kNotificationTitle
);
65 platform_data
.direction
=
66 PlatformNotificationData::NotificationDirectionLeftToRight
;
67 platform_data
.lang
= kNotificationLang
;
68 platform_data
.body
= base::ASCIIToUTF16(kNotificationBody
);
69 platform_data
.tag
= kNotificationTag
;
70 platform_data
.icon
= GURL(kNotificationIconUrl
);
71 platform_data
.silent
= true;
73 blink::WebNotificationData web_data
= ToWebNotificationData(platform_data
);
74 EXPECT_EQ(kNotificationTitle
, web_data
.title
);
75 EXPECT_EQ(blink::WebNotificationData::DirectionLeftToRight
,
77 EXPECT_EQ(kNotificationLang
, web_data
.lang
);
78 EXPECT_EQ(kNotificationBody
, web_data
.body
);
79 EXPECT_EQ(kNotificationTag
, web_data
.tag
);
80 EXPECT_EQ(kNotificationIconUrl
, web_data
.icon
.string());
81 EXPECT_TRUE(web_data
.silent
);
84 TEST(NotificationDataConversionsTest
, ToWebNotificationDataDirectionality
) {
85 PlatformNotificationData platform_data
;
86 platform_data
.direction
=
87 PlatformNotificationData::NotificationDirectionLeftToRight
;
89 blink::WebNotificationData web_data
= ToWebNotificationData(platform_data
);
90 EXPECT_EQ(blink::WebNotificationData::DirectionLeftToRight
,
93 platform_data
.direction
=
94 PlatformNotificationData::NotificationDirectionRightToLeft
;
96 web_data
= ToWebNotificationData(platform_data
);
97 EXPECT_EQ(blink::WebNotificationData::DirectionRightToLeft
,
101 } // namespace content