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

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

Issue 2872053002: Linux native notifications: Support image notifications (Closed)
Patch Set: Rebase Created 3 years, 7 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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_platform_bridge_linux.h" 5 #include "chrome/browser/notifications/notification_platform_bridge_linux.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 29 matching lines...) Expand all
40 gfx::Image(), 40 gfx::Image(),
41 message_center::NotifierId(GURL()), 41 message_center::NotifierId(GURL()),
42 base::string16(), 42 base::string16(),
43 GURL(), 43 GURL(),
44 id, 44 id,
45 message_center::RichNotificationData(), 45 message_center::RichNotificationData(),
46 new MockNotificationDelegate(id)) {} 46 new MockNotificationDelegate(id)) {}
47 47
48 Notification GetResult() { return notification_; } 48 Notification GetResult() { return notification_; }
49 49
50 NotificationBuilder& SetItems(
51 const std::vector<message_center::NotificationItem>& items) {
52 notification_.set_items(items);
53 return *this;
54 }
55
56 NotificationBuilder& SetNeverTimeout(bool never_timeout) {
57 notification_.set_never_timeout(never_timeout);
58 return *this;
59 }
60
50 NotificationBuilder& SetProgress(int progress) { 61 NotificationBuilder& SetProgress(int progress) {
51 notification_.set_progress(progress); 62 notification_.set_progress(progress);
52 return *this; 63 return *this;
53 } 64 }
54 65
55 NotificationBuilder& SetTitle(const base::string16& title) { 66 NotificationBuilder& SetTitle(const base::string16& title) {
56 notification_.set_title(title); 67 notification_.set_title(title);
57 return *this; 68 return *this;
58 } 69 }
59 70
60 NotificationBuilder& SetType(message_center::NotificationType type) { 71 NotificationBuilder& SetType(message_center::NotificationType type) {
61 notification_.set_type(type); 72 notification_.set_type(type);
62 return *this; 73 return *this;
63 } 74 }
64 75
65 private: 76 private:
66 Notification notification_; 77 Notification notification_;
67 }; 78 };
68 79
69 struct NotificationRequest { 80 struct NotificationRequest {
70 std::string summary; 81 std::string summary;
82 std::string body;
83 int32_t expire_timeout = 0;
71 }; 84 };
72 85
73 NotificationRequest ParseRequest(dbus::MethodCall* method_call) { 86 NotificationRequest ParseRequest(dbus::MethodCall* method_call) {
74 // The "Notify" message must have type (susssasa{sv}i). 87 // The "Notify" message must have type (susssasa{sv}i).
75 // https://developer.gnome.org/notification-spec/#command-notify 88 // https://developer.gnome.org/notification-spec/#command-notify
76 NotificationRequest request; 89 NotificationRequest request;
77 90
78 dbus::MessageReader reader(method_call); 91 dbus::MessageReader reader(method_call);
79 std::string str; 92 std::string str;
80 uint32_t uint32; 93 uint32_t uint32;
81 int32_t int32;
82 EXPECT_TRUE(reader.PopString(&str)); // app_name 94 EXPECT_TRUE(reader.PopString(&str)); // app_name
83 EXPECT_TRUE(reader.PopUint32(&uint32)); // replaces_id 95 EXPECT_TRUE(reader.PopUint32(&uint32)); // replaces_id
84 EXPECT_TRUE(reader.PopString(&str)); // app_icon 96 EXPECT_TRUE(reader.PopString(&str)); // app_icon
85 EXPECT_TRUE(reader.PopString(&request.summary)); // summary 97 EXPECT_TRUE(reader.PopString(&request.summary)); // summary
86 EXPECT_TRUE(reader.PopString(&str)); // body 98 EXPECT_TRUE(reader.PopString(&request.body)); // body
87 99
88 { 100 {
89 dbus::MessageReader actions_reader(nullptr); 101 dbus::MessageReader actions_reader(nullptr);
90 EXPECT_TRUE(reader.PopArray(&actions_reader)); 102 EXPECT_TRUE(reader.PopArray(&actions_reader));
91 while (actions_reader.HasMoreData()) { 103 while (actions_reader.HasMoreData()) {
92 // Actions come in pairs. 104 // Actions come in pairs.
93 EXPECT_TRUE(actions_reader.PopString(&str)); 105 EXPECT_TRUE(actions_reader.PopString(&str));
94 EXPECT_TRUE(actions_reader.PopString(&str)); 106 EXPECT_TRUE(actions_reader.PopString(&str));
95 } 107 }
96 } 108 }
97 109
98 { 110 {
99 dbus::MessageReader hints_reader(nullptr); 111 dbus::MessageReader hints_reader(nullptr);
100 EXPECT_TRUE(reader.PopArray(&hints_reader)); 112 EXPECT_TRUE(reader.PopArray(&hints_reader));
101 while (hints_reader.HasMoreData()) { 113 while (hints_reader.HasMoreData()) {
102 dbus::MessageReader dict_entry_reader(nullptr); 114 dbus::MessageReader dict_entry_reader(nullptr);
103 EXPECT_TRUE(hints_reader.PopDictEntry(&dict_entry_reader)); 115 EXPECT_TRUE(hints_reader.PopDictEntry(&dict_entry_reader));
104 EXPECT_TRUE(dict_entry_reader.PopString(&str)); 116 EXPECT_TRUE(dict_entry_reader.PopString(&str));
105 dbus::MessageReader variant_reader(nullptr); 117 dbus::MessageReader variant_reader(nullptr);
106 EXPECT_TRUE(dict_entry_reader.PopVariant(&variant_reader)); 118 EXPECT_TRUE(dict_entry_reader.PopVariant(&variant_reader));
107 EXPECT_FALSE(dict_entry_reader.HasMoreData()); 119 EXPECT_FALSE(dict_entry_reader.HasMoreData());
108 } 120 }
109 } 121 }
110 122
111 EXPECT_TRUE(reader.PopInt32(&int32)); // expire_timeout 123 EXPECT_TRUE(reader.PopInt32(&request.expire_timeout));
112 EXPECT_FALSE(reader.HasMoreData()); 124 EXPECT_FALSE(reader.HasMoreData());
113 125
114 return request; 126 return request;
115 } 127 }
116 128
117 dbus::Response* GetIdResponse(uint32_t id) { 129 dbus::Response* GetIdResponse(uint32_t id) {
118 dbus::Response* response = dbus::Response::CreateEmpty().release(); 130 dbus::Response* response = dbus::Response::CreateEmpty().release();
119 dbus::MessageWriter writer(response); 131 dbus::MessageWriter writer(response);
120 writer.AppendUint32(id); 132 writer.AppendUint32(id);
121 return response; 133 return response;
(...skipping 16 matching lines...) Expand all
138 ACTION_P(OnGetServerInformation, spec_version) { 150 ACTION_P(OnGetServerInformation, spec_version) {
139 dbus::Response* response = dbus::Response::CreateEmpty().release(); 151 dbus::Response* response = dbus::Response::CreateEmpty().release();
140 dbus::MessageWriter writer(response); 152 dbus::MessageWriter writer(response);
141 writer.AppendString(""); // name 153 writer.AppendString(""); // name
142 writer.AppendString(""); // vendor 154 writer.AppendString(""); // vendor
143 writer.AppendString(""); // version 155 writer.AppendString(""); // version
144 writer.AppendString(spec_version); 156 writer.AppendString(spec_version);
145 return response; 157 return response;
146 } 158 }
147 159
148 ACTION_P(OnNotify, id) { 160 ACTION_P2(OnNotify, verifier, id) {
149 ParseRequest(arg0); 161 verifier(ParseRequest(arg0));
150 return GetIdResponse(id); 162 return GetIdResponse(id);
151 } 163 }
152 164
153 ACTION(OnCloseNotification) { 165 ACTION(OnCloseNotification) {
154 // The "CloseNotification" message must have type (u). 166 // The "CloseNotification" message must have type (u).
155 // https://developer.gnome.org/notification-spec/#command-close-notification 167 // https://developer.gnome.org/notification-spec/#command-close-notification
156 dbus::MethodCall* method_call = arg0; 168 dbus::MethodCall* method_call = arg0;
157 dbus::MessageReader reader(method_call); 169 dbus::MessageReader reader(method_call);
158 uint32_t uint32; 170 uint32_t uint32;
159 EXPECT_TRUE(reader.PopUint32(&uint32)); 171 EXPECT_TRUE(reader.PopUint32(&uint32));
(...skipping 20 matching lines...) Expand all
180 mock_bus_.get(), kFreedesktopNotificationsName, 192 mock_bus_.get(), kFreedesktopNotificationsName,
181 dbus::ObjectPath(kFreedesktopNotificationsPath)); 193 dbus::ObjectPath(kFreedesktopNotificationsPath));
182 194
183 EXPECT_CALL(*mock_bus_.get(), 195 EXPECT_CALL(*mock_bus_.get(),
184 GetObjectProxy(kFreedesktopNotificationsName, 196 GetObjectProxy(kFreedesktopNotificationsName,
185 dbus::ObjectPath(kFreedesktopNotificationsPath))) 197 dbus::ObjectPath(kFreedesktopNotificationsPath)))
186 .WillOnce(Return(mock_notification_proxy_.get())); 198 .WillOnce(Return(mock_notification_proxy_.get()));
187 199
188 EXPECT_CALL(*mock_notification_proxy_.get(), 200 EXPECT_CALL(*mock_notification_proxy_.get(),
189 MockCallMethodAndBlock(Calls("GetCapabilities"), _)) 201 MockCallMethodAndBlock(Calls("GetCapabilities"), _))
190 .WillOnce(OnGetCapabilities(std::vector<std::string>())); 202 .WillOnce(OnGetCapabilities(std::vector<std::string>{"body"}));
191 203
192 EXPECT_CALL(*mock_notification_proxy_.get(), 204 EXPECT_CALL(*mock_notification_proxy_.get(),
193 MockCallMethodAndBlock(Calls("GetServerInformation"), _)) 205 MockCallMethodAndBlock(Calls("GetServerInformation"), _))
194 .WillOnce(OnGetServerInformation("1.2")); 206 .WillOnce(OnGetServerInformation("1.2"));
195 207
196 EXPECT_CALL( 208 EXPECT_CALL(
197 *mock_notification_proxy_.get(), 209 *mock_notification_proxy_.get(),
198 ConnectToSignal(kFreedesktopNotificationsName, "ActionInvoked", _, _)) 210 ConnectToSignal(kFreedesktopNotificationsName, "ActionInvoked", _, _))
199 .WillOnce(RegisterSignalCallback(&action_invoked_callback_)); 211 .WillOnce(RegisterSignalCallback(&action_invoked_callback_));
200 212
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinuxTest); 245 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinuxTest);
234 }; 246 };
235 247
236 TEST_F(NotificationPlatformBridgeLinuxTest, SetUpAndTearDown) { 248 TEST_F(NotificationPlatformBridgeLinuxTest, SetUpAndTearDown) {
237 CreateNotificationBridgeLinux(); 249 CreateNotificationBridgeLinux();
238 } 250 }
239 251
240 TEST_F(NotificationPlatformBridgeLinuxTest, NotifyAndCloseFormat) { 252 TEST_F(NotificationPlatformBridgeLinuxTest, NotifyAndCloseFormat) {
241 EXPECT_CALL(*mock_notification_proxy_.get(), 253 EXPECT_CALL(*mock_notification_proxy_.get(),
242 MockCallMethodAndBlock(Calls("Notify"), _)) 254 MockCallMethodAndBlock(Calls("Notify"), _))
243 .WillOnce(OnNotify(1)); 255 .WillOnce(OnNotify([](const NotificationRequest&) {}, 1));
244 EXPECT_CALL(*mock_notification_proxy_.get(), 256 EXPECT_CALL(*mock_notification_proxy_.get(),
245 MockCallMethodAndBlock(Calls("CloseNotification"), _)) 257 MockCallMethodAndBlock(Calls("CloseNotification"), _))
246 .WillOnce(OnCloseNotification()); 258 .WillOnce(OnCloseNotification());
247 259
248 CreateNotificationBridgeLinux(); 260 CreateNotificationBridgeLinux();
249 notification_bridge_linux_->Display(NotificationCommon::PERSISTENT, "", "", 261 notification_bridge_linux_->Display(NotificationCommon::PERSISTENT, "", "",
250 false, 262 false,
251 NotificationBuilder("").GetResult()); 263 NotificationBuilder("").GetResult());
252 notification_bridge_linux_->Close("", ""); 264 notification_bridge_linux_->Close("", "");
253 } 265 }
254 266
255 ACTION_P2(VerifySummary, summary, id) {
256 NotificationRequest request = ParseRequest(arg0);
257 EXPECT_EQ(summary, request.summary);
258 return GetIdResponse(id);
259 }
260
261 TEST_F(NotificationPlatformBridgeLinuxTest, ProgressPercentageAddedToSummary) { 267 TEST_F(NotificationPlatformBridgeLinuxTest, ProgressPercentageAddedToSummary) {
262 EXPECT_CALL(*mock_notification_proxy_.get(), 268 EXPECT_CALL(*mock_notification_proxy_.get(),
263 MockCallMethodAndBlock(Calls("Notify"), _)) 269 MockCallMethodAndBlock(Calls("Notify"), _))
264 .WillOnce(VerifySummary( 270 .WillOnce(OnNotify(
265 base::UTF16ToUTF8(base::FormatPercent(42)) + " - The Title", 1)); 271 [](const NotificationRequest& request) {
272 EXPECT_EQ(
273 base::UTF16ToUTF8(base::FormatPercent(42)) + " - The Title",
274 request.summary);
275 },
276 1));
266 277
267 CreateNotificationBridgeLinux(); 278 CreateNotificationBridgeLinux();
268 notification_bridge_linux_->Display( 279 notification_bridge_linux_->Display(
269 NotificationCommon::PERSISTENT, "", "", false, 280 NotificationCommon::PERSISTENT, "", "", false,
270 NotificationBuilder("") 281 NotificationBuilder("")
271 .SetType(message_center::NOTIFICATION_TYPE_PROGRESS) 282 .SetType(message_center::NOTIFICATION_TYPE_PROGRESS)
272 .SetProgress(42) 283 .SetProgress(42)
273 .SetTitle(base::UTF8ToUTF16("The Title")) 284 .SetTitle(base::UTF8ToUTF16("The Title"))
274 .GetResult()); 285 .GetResult());
275 } 286 }
287
288 TEST_F(NotificationPlatformBridgeLinuxTest, NotificationListItemsInBody) {
289 EXPECT_CALL(*mock_notification_proxy_.get(),
290 MockCallMethodAndBlock(Calls("Notify"), _))
291 .WillOnce(OnNotify(
292 [](const NotificationRequest& request) {
293 EXPECT_EQ("abc - 123\ndef - 456", request.body);
294 },
295 1));
296
297 CreateNotificationBridgeLinux();
298 notification_bridge_linux_->Display(
299 NotificationCommon::PERSISTENT, "", "", false,
300 NotificationBuilder("")
301 .SetType(message_center::NOTIFICATION_TYPE_MULTIPLE)
302 .SetItems(std::vector<message_center::NotificationItem>{
303 {base::UTF8ToUTF16("abc"), base::UTF8ToUTF16("123")},
304 {base::UTF8ToUTF16("def"), base::UTF8ToUTF16("456")}})
305 .GetResult());
306 }
307
308 TEST_F(NotificationPlatformBridgeLinuxTest, NotificationTimeouts) {
309 const int32_t kExpireTimeoutDefault = -1;
310 const int32_t kExpireTimeoutNever = 0;
311 EXPECT_CALL(*mock_notification_proxy_.get(),
312 MockCallMethodAndBlock(Calls("Notify"), _))
313 .WillOnce(OnNotify(
314 [=](const NotificationRequest& request) {
315 EXPECT_EQ(kExpireTimeoutDefault, request.expire_timeout);
316 },
317 1))
318 .WillOnce(OnNotify(
319 [=](const NotificationRequest& request) {
320 EXPECT_EQ(kExpireTimeoutNever, request.expire_timeout);
321 },
322 2));
323
324 CreateNotificationBridgeLinux();
325 notification_bridge_linux_->Display(
326 NotificationCommon::PERSISTENT, "", "", false,
327 NotificationBuilder("1").SetNeverTimeout(false).GetResult());
328 notification_bridge_linux_->Display(
329 NotificationCommon::PERSISTENT, "", "", false,
330 NotificationBuilder("2").SetNeverTimeout(true).GetResult());
331 }
Peter Beverloo 2017/05/15 16:16:00 Should there be a test for big image here?
Tom (Use chromium acct) 2017/05/15 19:18:39 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698