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

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

Issue 2138873002: Add tests for the Display operation of the mac notification bridge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/notifications/notification_test_util.h" 5 #include "chrome/browser/notifications/notification_test_util.h"
6 6
7 #include "base/strings/utf_string_conversions.h"
8 #include "third_party/skia/include/core/SkBitmap.h"
9 #include "url/gurl.h"
10
7 MockNotificationDelegate::MockNotificationDelegate(const std::string& id) 11 MockNotificationDelegate::MockNotificationDelegate(const std::string& id)
8 : id_(id) {} 12 : id_(id) {}
9 13
10 MockNotificationDelegate::~MockNotificationDelegate() {} 14 MockNotificationDelegate::~MockNotificationDelegate() {}
11 15
12 std::string MockNotificationDelegate::id() const { return id_; } 16 std::string MockNotificationDelegate::id() const { return id_; }
13 17
14 // ----------------------------------------------------------------------------- 18 // -----------------------------------------------------------------------------
15 19
16 StubNotificationUIManager::StubNotificationUIManager() {} 20 StubNotificationUIManager::StubNotificationUIManager() {}
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 bool StubNotificationUIManager::CancelAllByProfile(ProfileID profile_id) { 132 bool StubNotificationUIManager::CancelAllByProfile(ProfileID profile_id) {
129 NOTIMPLEMENTED(); 133 NOTIMPLEMENTED();
130 return false; 134 return false;
131 } 135 }
132 136
133 void StubNotificationUIManager::CancelAll() { 137 void StubNotificationUIManager::CancelAll() {
134 for (const auto& pair : notifications_) 138 for (const auto& pair : notifications_)
135 pair.first.delegate()->Close(false /* by_user */); 139 pair.first.delegate()->Close(false /* by_user */);
136 notifications_.clear(); 140 notifications_.clear();
137 } 141 }
142
143 std::unique_ptr<Notification> NotificationGenerator::CreateNotification(
144 message_center::NotificationType type) {
145 return NotificationGenerator::CreateNotification(
146 "Title", "This is a message.", "I am a context message.", "Button 1",
147 "Button 2", type);
148 }
149
150 // static
151 std::unique_ptr<Notification> NotificationGenerator::CreateNotification(
152 const std::string& title,
153 const std::string& subtitle,
154 const std::string& context,
155 const std::string& button1,
156 const std::string& button2,
157 message_center::NotificationType type) {
158 message_center::RichNotificationData optional_fields;
159 optional_fields.priority = 1;
160 optional_fields.context_message = base::UTF8ToUTF16(context);
161 optional_fields.timestamp = base::Time::FromDoubleT(12345678.9);
162 if (!button1.empty()) {
163 optional_fields.buttons.push_back(
164 message_center::ButtonInfo(base::UTF8ToUTF16(button1)));
165 if (!button2.empty()) {
166 optional_fields.buttons.push_back(
167 message_center::ButtonInfo(base::UTF8ToUTF16(button2)));
168 }
169 }
170 optional_fields.clickable = false;
171
172 if (type == message_center::NOTIFICATION_TYPE_IMAGE)
173 optional_fields.image = gfx::Image();
174 if (type == message_center::NOTIFICATION_TYPE_MULTIPLE) {
175 optional_fields.items.push_back(
176 message_center::NotificationItem(base::UTF8ToUTF16("Item 1 Title"),
177 base::UTF8ToUTF16("Item 1 Message")));
178 optional_fields.items.push_back(
179 message_center::NotificationItem(base::UTF8ToUTF16("Item 2 Title"),
180 base::UTF8ToUTF16("Item 2 Message")));
181 }
182 if (type == message_center::NOTIFICATION_TYPE_PROGRESS)
183 optional_fields.progress = 50;
184
185 NotificationDelegate* delegate(new MockNotificationDelegate("id1"));
186
187 SkBitmap bitmap;
188 bitmap.allocN32Pixels(1, 1);
189 bitmap.eraseColor(SkColorSetRGB(1, 2, 3));
190 gfx::Image icon = gfx::Image::CreateFrom1xBitmap(bitmap);
191
192 std::unique_ptr<Notification> notification(new Notification(
193 type, base::UTF8ToUTF16(title), base::UTF8ToUTF16(subtitle), icon,
194 message_center::NotifierId(message_center::NotifierId::APPLICATION,
195 "Notifier 1"),
196 base::UTF8ToUTF16("Notifier's Name"), GURL(), "id1", optional_fields,
197 delegate));
198
199 return notification;
200 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698