Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / notifications / notification_conversion_helper_unittest.cc
blobd251b2fc04abb1fb4ed6872c61ae1dad2e50a60c
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 "chrome/browser/notifications/notification_conversion_helper.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/notifications/notification.h"
9 #include "chrome/browser/notifications/notification_test_util.h"
10 #include "chrome/common/extensions/api/notifications.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "ui/message_center/notification.h"
14 #include "ui/message_center/notification_types.h"
15 #include "url/gurl.h"
17 class NotificationConversionHelperTest : public testing::Test {
18 public:
19 NotificationConversionHelperTest() {}
21 void SetUp() override {}
23 void TearDown() override {}
25 protected:
26 scoped_ptr<Notification> CreateNotification(
27 message_center::NotificationType type) {
28 message_center::RichNotificationData optional_fields;
29 optional_fields.priority = 1;
30 optional_fields.context_message =
31 base::UTF8ToUTF16("I am a context message.");
32 optional_fields.timestamp = base::Time::FromDoubleT(12345678.9);
33 optional_fields.buttons.push_back(
34 message_center::ButtonInfo(base::UTF8ToUTF16("Button 1")));
35 optional_fields.buttons.push_back(
36 message_center::ButtonInfo(base::UTF8ToUTF16("Button 2")));
37 optional_fields.clickable = false;
39 if (type == message_center::NOTIFICATION_TYPE_IMAGE)
40 optional_fields.image = gfx::Image();
41 if (type == message_center::NOTIFICATION_TYPE_MULTIPLE) {
42 optional_fields.items.push_back(message_center::NotificationItem(
43 base::UTF8ToUTF16("Item 1 Title"),
44 base::UTF8ToUTF16("Item 1 Message")));
45 optional_fields.items.push_back(message_center::NotificationItem(
46 base::UTF8ToUTF16("Item 2 Title"),
47 base::UTF8ToUTF16("Item 2 Message")));
49 if (type == message_center::NOTIFICATION_TYPE_PROGRESS)
50 optional_fields.progress = 50;
52 NotificationDelegate* delegate(new MockNotificationDelegate("id1"));
54 SkBitmap bitmap;
55 bitmap.allocN32Pixels(1, 1);
56 bitmap.eraseColor(SkColorSetRGB(1, 2, 3));
57 gfx::Image icon = gfx::Image::CreateFrom1xBitmap(bitmap);
59 scoped_ptr<Notification> notification(new Notification(
60 type, base::UTF8ToUTF16("Title"),
61 base::UTF8ToUTF16("This is a message."), icon,
62 message_center::NotifierId(message_center::NotifierId::APPLICATION,
63 "Notifier 1"),
64 base::UTF8ToUTF16("Notifier's Name"), GURL(), "id1", optional_fields,
65 delegate));
67 return notification.Pass();
70 private:
71 DISALLOW_COPY_AND_ASSIGN(NotificationConversionHelperTest);
74 TEST_F(NotificationConversionHelperTest, NotificationToNotificationOptions) {
75 // Create a notification of image type
76 scoped_ptr<Notification> notification1 =
77 CreateNotification(message_center::NOTIFICATION_TYPE_IMAGE);
78 scoped_ptr<extensions::api::notifications::NotificationOptions> options1(
79 new extensions::api::notifications::NotificationOptions());
80 NotificationConversionHelper::NotificationToNotificationOptions(
81 *(notification1), options1.get());
83 EXPECT_EQ(options1->type,
84 extensions::api::notifications::TEMPLATE_TYPE_IMAGE);
85 EXPECT_EQ(*(options1->title), "Title");
86 EXPECT_EQ(*(options1->message), "This is a message.");
87 EXPECT_EQ(*(options1->priority), 1);
88 EXPECT_EQ(*(options1->context_message), "I am a context message.");
89 EXPECT_FALSE(*(options1->is_clickable));
90 EXPECT_EQ(*(options1->event_time), 12345678.9);
91 EXPECT_EQ(options1->buttons->at(0)->title, "Button 1");
92 EXPECT_EQ(options1->buttons->at(1)->title, "Button 2");
94 EXPECT_EQ(options1->icon_bitmap->width, 1);
95 EXPECT_EQ(options1->icon_bitmap->height, 1);
97 // Create a notification of progress type
98 scoped_ptr<Notification> notification2 =
99 CreateNotification(message_center::NOTIFICATION_TYPE_PROGRESS);
100 scoped_ptr<extensions::api::notifications::NotificationOptions> options2(
101 new extensions::api::notifications::NotificationOptions());
102 NotificationConversionHelper::NotificationToNotificationOptions(
103 *(notification2), options2.get());
104 EXPECT_EQ(options2->type,
105 extensions::api::notifications::TEMPLATE_TYPE_PROGRESS);
106 EXPECT_EQ(*(options2->progress), 50);
108 // Create a notification of multiple type
109 scoped_ptr<Notification> notification3 =
110 CreateNotification(message_center::NOTIFICATION_TYPE_MULTIPLE);
111 scoped_ptr<extensions::api::notifications::NotificationOptions> options3(
112 new extensions::api::notifications::NotificationOptions());
113 NotificationConversionHelper::NotificationToNotificationOptions(
114 *(notification3), options3.get());
115 EXPECT_EQ(options3->type, extensions::api::notifications::TEMPLATE_TYPE_LIST);
116 EXPECT_EQ(options3->items->at(0)->title, "Item 1 Title");
117 EXPECT_EQ(options3->items->at(0)->message, "Item 1 Message");
118 EXPECT_EQ(options3->items->at(1)->title, "Item 2 Title");
119 EXPECT_EQ(options3->items->at(1)->message, "Item 2 Message");