Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / notifications / notification_conversion_helper_unittest.cc
blobacc2d2463353344050cb666eea851e2e4bae3bde
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,
61 GURL(),
62 base::UTF8ToUTF16("Title"),
63 base::UTF8ToUTF16("This is a message."),
64 icon,
65 message_center::NotifierId(message_center::NotifierId::APPLICATION,
66 "Notifier 1"),
67 base::UTF8ToUTF16("Notifier's Name"),
68 "id1",
69 optional_fields,
70 delegate));
72 return notification.Pass();
75 private:
76 DISALLOW_COPY_AND_ASSIGN(NotificationConversionHelperTest);
79 TEST_F(NotificationConversionHelperTest, NotificationToNotificationOptions) {
80 // Create a notification of image type
81 scoped_ptr<Notification> notification1 =
82 CreateNotification(message_center::NOTIFICATION_TYPE_IMAGE);
83 scoped_ptr<extensions::api::notifications::NotificationOptions> options1(
84 new extensions::api::notifications::NotificationOptions());
85 NotificationConversionHelper::NotificationToNotificationOptions(
86 *(notification1), options1.get());
88 EXPECT_EQ(options1->type,
89 extensions::api::notifications::TEMPLATE_TYPE_IMAGE);
90 EXPECT_EQ(*(options1->title), "Title");
91 EXPECT_EQ(*(options1->message), "This is a message.");
92 EXPECT_EQ(*(options1->priority), 1);
93 EXPECT_EQ(*(options1->context_message), "I am a context message.");
94 EXPECT_FALSE(*(options1->is_clickable));
95 EXPECT_EQ(*(options1->event_time), 12345678.9);
96 EXPECT_EQ(options1->buttons->at(0)->title, "Button 1");
97 EXPECT_EQ(options1->buttons->at(1)->title, "Button 2");
99 EXPECT_EQ(options1->icon_bitmap->width, 1);
100 EXPECT_EQ(options1->icon_bitmap->height, 1);
102 // Create a notification of progress type
103 scoped_ptr<Notification> notification2 =
104 CreateNotification(message_center::NOTIFICATION_TYPE_PROGRESS);
105 scoped_ptr<extensions::api::notifications::NotificationOptions> options2(
106 new extensions::api::notifications::NotificationOptions());
107 NotificationConversionHelper::NotificationToNotificationOptions(
108 *(notification2), options2.get());
109 EXPECT_EQ(options2->type,
110 extensions::api::notifications::TEMPLATE_TYPE_PROGRESS);
111 EXPECT_EQ(*(options2->progress), 50);
113 // Create a notification of multiple type
114 scoped_ptr<Notification> notification3 =
115 CreateNotification(message_center::NOTIFICATION_TYPE_MULTIPLE);
116 scoped_ptr<extensions::api::notifications::NotificationOptions> options3(
117 new extensions::api::notifications::NotificationOptions());
118 NotificationConversionHelper::NotificationToNotificationOptions(
119 *(notification3), options3.get());
120 EXPECT_EQ(options3->type, extensions::api::notifications::TEMPLATE_TYPE_LIST);
121 EXPECT_EQ(options3->items->at(0)->title, "Item 1 Title");
122 EXPECT_EQ(options3->items->at(0)->message, "Item 1 Message");
123 EXPECT_EQ(options3->items->at(1)->title, "Item 2 Title");
124 EXPECT_EQ(options3->items->at(1)->message, "Item 2 Message");