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

Side by Side Diff: chrome/browser/notifications/notification_conversion_helper_unittest.cc

Issue 441753002: Route newly created notifications to notification provider API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bug fix Created 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/notifications/notification_conversion_helper.h"
6
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"
16
17 class NotificationConversionHelperTest : public testing::Test {
18 public:
19 NotificationConversionHelperTest() {}
20
21 virtual void SetUp() OVERRIDE {}
22
23 virtual void TearDown() OVERRIDE {}
24
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;
38 optional_fields.small_image = gfx::Image();
39
40 if (type == message_center::NOTIFICATION_TYPE_IMAGE)
41 optional_fields.image = gfx::Image();
42 if (type == message_center::NOTIFICATION_TYPE_MULTIPLE) {
43 optional_fields.items.push_back(message_center::NotificationItem(
44 base::UTF8ToUTF16("Item 1 Title"),
45 base::UTF8ToUTF16("Item 1 Message")));
46 optional_fields.items.push_back(message_center::NotificationItem(
47 base::UTF8ToUTF16("Item 2 Title"),
48 base::UTF8ToUTF16("Item 2 Message")));
49 }
50 if (type == message_center::NOTIFICATION_TYPE_PROGRESS)
51 optional_fields.progress = 50;
52
53 NotificationDelegate* delegate(new MockNotificationDelegate("id1"));
54
55 SkBitmap bitmap;
56 bitmap.allocN32Pixels(1, 1);
57 bitmap.eraseColor(SkColorSetRGB(1, 2, 3));
58 gfx::Image icon = gfx::Image::CreateFrom1xBitmap(bitmap);
59
60 scoped_ptr<Notification> notification(new Notification(
61 type,
62 GURL(),
63 base::UTF8ToUTF16("Title"),
64 base::UTF8ToUTF16("This is a message."),
65 icon,
66 blink::WebTextDirectionDefault,
67 message_center::NotifierId(message_center::NotifierId::APPLICATION,
68 "Notifier 1"),
69 base::UTF8ToUTF16("Notifier's Name"),
70 base::UTF8ToUTF16("id1"),
71 optional_fields,
72 delegate));
73
74 return notification.Pass();
75 }
76
77 private:
78 DISALLOW_COPY_AND_ASSIGN(NotificationConversionHelperTest);
79 };
80
81 TEST_F(NotificationConversionHelperTest, NotificationToNotificationOptions) {
82 NotificationConversionHelper conversion_helper;
83
84 // Create a notification of image type
85 scoped_ptr<Notification> notification1 =
86 CreateNotification(message_center::NOTIFICATION_TYPE_IMAGE);
87 scoped_ptr<extensions::api::notifications::NotificationOptions> options1(
88 new extensions::api::notifications::NotificationOptions());
89 conversion_helper.NotificationToNotificationOptions(*(notification1),
90 options1.get());
91
92 EXPECT_EQ(options1->type,
93 extensions::api::notifications::TEMPLATE_TYPE_IMAGE);
94 EXPECT_EQ(*(options1->title), "Title");
95 EXPECT_EQ(*(options1->message), "This is a message.");
96 EXPECT_EQ(*(options1->priority), 1);
97 EXPECT_EQ(*(options1->context_message), "I am a context message.");
98 EXPECT_FALSE(*(options1->is_clickable));
99 EXPECT_EQ(*(options1->event_time), 12345678.9);
100 EXPECT_EQ(options1->buttons->at(0)->title, "Button 1");
101 EXPECT_EQ(options1->buttons->at(1)->title, "Button 2");
102
103 EXPECT_EQ(options1->icon_bitmap->width, 1);
104 EXPECT_EQ(options1->icon_bitmap->height, 1);
105
106 // Create a notification of progress type
107 scoped_ptr<Notification> notification2 =
108 CreateNotification(message_center::NOTIFICATION_TYPE_PROGRESS);
109 scoped_ptr<extensions::api::notifications::NotificationOptions> options2(
110 new extensions::api::notifications::NotificationOptions());
111 conversion_helper.NotificationToNotificationOptions(*(notification2),
112 options2.get());
113 EXPECT_EQ(options2->type,
114 extensions::api::notifications::TEMPLATE_TYPE_PROGRESS);
115 EXPECT_EQ(*(options2->progress), 50);
116
117 // Create a notification of multiple type
118 scoped_ptr<Notification> notification3 =
119 CreateNotification(message_center::NOTIFICATION_TYPE_MULTIPLE);
120 scoped_ptr<extensions::api::notifications::NotificationOptions> options3(
121 new extensions::api::notifications::NotificationOptions());
122 conversion_helper.NotificationToNotificationOptions(*(notification3),
123 options3.get());
124 EXPECT_EQ(options3->type, extensions::api::notifications::TEMPLATE_TYPE_LIST);
125 EXPECT_EQ(options3->items->at(0)->title, "Item 1 Title");
126 EXPECT_EQ(options3->items->at(0)->message, "Item 1 Message");
127 EXPECT_EQ(options3->items->at(1)->title, "Item 2 Title");
128 EXPECT_EQ(options3->items->at(1)->message, "Item 2 Message");
129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698