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

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

Issue 2875443002: Linux native notifications: Support list 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
« no previous file with comments | « chrome/browser/notifications/notification_platform_bridge_linux.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
50 NotificationBuilder& SetProgress(int progress) { 56 NotificationBuilder& SetProgress(int progress) {
51 notification_.set_progress(progress); 57 notification_.set_progress(progress);
52 return *this; 58 return *this;
53 } 59 }
54 60
55 NotificationBuilder& SetTitle(const base::string16& title) { 61 NotificationBuilder& SetTitle(const base::string16& title) {
56 notification_.set_title(title); 62 notification_.set_title(title);
57 return *this; 63 return *this;
58 } 64 }
59 65
60 NotificationBuilder& SetType(message_center::NotificationType type) { 66 NotificationBuilder& SetType(message_center::NotificationType type) {
61 notification_.set_type(type); 67 notification_.set_type(type);
62 return *this; 68 return *this;
63 } 69 }
64 70
65 private: 71 private:
66 Notification notification_; 72 Notification notification_;
67 }; 73 };
68 74
69 struct NotificationRequest { 75 struct NotificationRequest {
70 std::string summary; 76 std::string summary;
77 std::string body;
71 }; 78 };
72 79
73 NotificationRequest ParseRequest(dbus::MethodCall* method_call) { 80 NotificationRequest ParseRequest(dbus::MethodCall* method_call) {
74 // The "Notify" message must have type (susssasa{sv}i). 81 // The "Notify" message must have type (susssasa{sv}i).
75 // https://developer.gnome.org/notification-spec/#command-notify 82 // https://developer.gnome.org/notification-spec/#command-notify
76 NotificationRequest request; 83 NotificationRequest request;
77 84
78 dbus::MessageReader reader(method_call); 85 dbus::MessageReader reader(method_call);
79 std::string str; 86 std::string str;
80 uint32_t uint32; 87 uint32_t uint32;
81 int32_t int32; 88 int32_t int32;
82 EXPECT_TRUE(reader.PopString(&str)); // app_name 89 EXPECT_TRUE(reader.PopString(&str)); // app_name
83 EXPECT_TRUE(reader.PopUint32(&uint32)); // replaces_id 90 EXPECT_TRUE(reader.PopUint32(&uint32)); // replaces_id
84 EXPECT_TRUE(reader.PopString(&str)); // app_icon 91 EXPECT_TRUE(reader.PopString(&str)); // app_icon
85 EXPECT_TRUE(reader.PopString(&request.summary)); // summary 92 EXPECT_TRUE(reader.PopString(&request.summary)); // summary
86 EXPECT_TRUE(reader.PopString(&str)); // body 93 EXPECT_TRUE(reader.PopString(&request.body)); // body
87 94
88 { 95 {
89 dbus::MessageReader actions_reader(nullptr); 96 dbus::MessageReader actions_reader(nullptr);
90 EXPECT_TRUE(reader.PopArray(&actions_reader)); 97 EXPECT_TRUE(reader.PopArray(&actions_reader));
91 while (actions_reader.HasMoreData()) { 98 while (actions_reader.HasMoreData()) {
92 // Actions come in pairs. 99 // Actions come in pairs.
93 EXPECT_TRUE(actions_reader.PopString(&str)); 100 EXPECT_TRUE(actions_reader.PopString(&str));
94 EXPECT_TRUE(actions_reader.PopString(&str)); 101 EXPECT_TRUE(actions_reader.PopString(&str));
95 } 102 }
96 } 103 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 ACTION_P(OnGetServerInformation, spec_version) { 145 ACTION_P(OnGetServerInformation, spec_version) {
139 dbus::Response* response = dbus::Response::CreateEmpty().release(); 146 dbus::Response* response = dbus::Response::CreateEmpty().release();
140 dbus::MessageWriter writer(response); 147 dbus::MessageWriter writer(response);
141 writer.AppendString(""); // name 148 writer.AppendString(""); // name
142 writer.AppendString(""); // vendor 149 writer.AppendString(""); // vendor
143 writer.AppendString(""); // version 150 writer.AppendString(""); // version
144 writer.AppendString(spec_version); 151 writer.AppendString(spec_version);
145 return response; 152 return response;
146 } 153 }
147 154
148 ACTION_P(OnNotify, id) { 155 ACTION_P2(OnNotify, verifier, id) {
149 ParseRequest(arg0); 156 verifier(ParseRequest(arg0));
150 return GetIdResponse(id); 157 return GetIdResponse(id);
151 } 158 }
152 159
153 ACTION(OnCloseNotification) { 160 ACTION(OnCloseNotification) {
154 // The "CloseNotification" message must have type (u). 161 // The "CloseNotification" message must have type (u).
155 // https://developer.gnome.org/notification-spec/#command-close-notification 162 // https://developer.gnome.org/notification-spec/#command-close-notification
156 dbus::MethodCall* method_call = arg0; 163 dbus::MethodCall* method_call = arg0;
157 dbus::MessageReader reader(method_call); 164 dbus::MessageReader reader(method_call);
158 uint32_t uint32; 165 uint32_t uint32;
159 EXPECT_TRUE(reader.PopUint32(&uint32)); 166 EXPECT_TRUE(reader.PopUint32(&uint32));
(...skipping 20 matching lines...) Expand all
180 mock_bus_.get(), kFreedesktopNotificationsName, 187 mock_bus_.get(), kFreedesktopNotificationsName,
181 dbus::ObjectPath(kFreedesktopNotificationsPath)); 188 dbus::ObjectPath(kFreedesktopNotificationsPath));
182 189
183 EXPECT_CALL(*mock_bus_.get(), 190 EXPECT_CALL(*mock_bus_.get(),
184 GetObjectProxy(kFreedesktopNotificationsName, 191 GetObjectProxy(kFreedesktopNotificationsName,
185 dbus::ObjectPath(kFreedesktopNotificationsPath))) 192 dbus::ObjectPath(kFreedesktopNotificationsPath)))
186 .WillOnce(Return(mock_notification_proxy_.get())); 193 .WillOnce(Return(mock_notification_proxy_.get()));
187 194
188 EXPECT_CALL(*mock_notification_proxy_.get(), 195 EXPECT_CALL(*mock_notification_proxy_.get(),
189 MockCallMethodAndBlock(Calls("GetCapabilities"), _)) 196 MockCallMethodAndBlock(Calls("GetCapabilities"), _))
190 .WillOnce(OnGetCapabilities(std::vector<std::string>())); 197 .WillOnce(OnGetCapabilities(std::vector<std::string>{"body"}));
191 198
192 EXPECT_CALL(*mock_notification_proxy_.get(), 199 EXPECT_CALL(*mock_notification_proxy_.get(),
193 MockCallMethodAndBlock(Calls("GetServerInformation"), _)) 200 MockCallMethodAndBlock(Calls("GetServerInformation"), _))
194 .WillOnce(OnGetServerInformation("1.2")); 201 .WillOnce(OnGetServerInformation("1.2"));
195 202
196 EXPECT_CALL( 203 EXPECT_CALL(
197 *mock_notification_proxy_.get(), 204 *mock_notification_proxy_.get(),
198 ConnectToSignal(kFreedesktopNotificationsName, "ActionInvoked", _, _)) 205 ConnectToSignal(kFreedesktopNotificationsName, "ActionInvoked", _, _))
199 .WillOnce(RegisterSignalCallback(&action_invoked_callback_)); 206 .WillOnce(RegisterSignalCallback(&action_invoked_callback_));
200 207
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinuxTest); 240 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeLinuxTest);
234 }; 241 };
235 242
236 TEST_F(NotificationPlatformBridgeLinuxTest, SetUpAndTearDown) { 243 TEST_F(NotificationPlatformBridgeLinuxTest, SetUpAndTearDown) {
237 CreateNotificationBridgeLinux(); 244 CreateNotificationBridgeLinux();
238 } 245 }
239 246
240 TEST_F(NotificationPlatformBridgeLinuxTest, NotifyAndCloseFormat) { 247 TEST_F(NotificationPlatformBridgeLinuxTest, NotifyAndCloseFormat) {
241 EXPECT_CALL(*mock_notification_proxy_.get(), 248 EXPECT_CALL(*mock_notification_proxy_.get(),
242 MockCallMethodAndBlock(Calls("Notify"), _)) 249 MockCallMethodAndBlock(Calls("Notify"), _))
243 .WillOnce(OnNotify(1)); 250 .WillOnce(OnNotify([](const NotificationRequest&) {}, 1));
244 EXPECT_CALL(*mock_notification_proxy_.get(), 251 EXPECT_CALL(*mock_notification_proxy_.get(),
245 MockCallMethodAndBlock(Calls("CloseNotification"), _)) 252 MockCallMethodAndBlock(Calls("CloseNotification"), _))
246 .WillOnce(OnCloseNotification()); 253 .WillOnce(OnCloseNotification());
247 254
248 CreateNotificationBridgeLinux(); 255 CreateNotificationBridgeLinux();
249 notification_bridge_linux_->Display(NotificationCommon::PERSISTENT, "", "", 256 notification_bridge_linux_->Display(NotificationCommon::PERSISTENT, "", "",
250 false, 257 false,
251 NotificationBuilder("").GetResult()); 258 NotificationBuilder("").GetResult());
252 notification_bridge_linux_->Close("", ""); 259 notification_bridge_linux_->Close("", "");
253 } 260 }
254 261
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) { 262 TEST_F(NotificationPlatformBridgeLinuxTest, ProgressPercentageAddedToSummary) {
262 EXPECT_CALL(*mock_notification_proxy_.get(), 263 EXPECT_CALL(*mock_notification_proxy_.get(),
263 MockCallMethodAndBlock(Calls("Notify"), _)) 264 MockCallMethodAndBlock(Calls("Notify"), _))
264 .WillOnce(VerifySummary( 265 .WillOnce(OnNotify(
265 base::UTF16ToUTF8(base::FormatPercent(42)) + " - The Title", 1)); 266 [](const NotificationRequest& request) {
267 EXPECT_EQ(
268 base::UTF16ToUTF8(base::FormatPercent(42)) + " - The Title",
269 request.summary);
270 },
271 1));
266 272
267 CreateNotificationBridgeLinux(); 273 CreateNotificationBridgeLinux();
268 notification_bridge_linux_->Display( 274 notification_bridge_linux_->Display(
269 NotificationCommon::PERSISTENT, "", "", false, 275 NotificationCommon::PERSISTENT, "", "", false,
270 NotificationBuilder("") 276 NotificationBuilder("")
271 .SetType(message_center::NOTIFICATION_TYPE_PROGRESS) 277 .SetType(message_center::NOTIFICATION_TYPE_PROGRESS)
272 .SetProgress(42) 278 .SetProgress(42)
273 .SetTitle(base::UTF8ToUTF16("The Title")) 279 .SetTitle(base::UTF8ToUTF16("The Title"))
274 .GetResult()); 280 .GetResult());
275 } 281 }
282
283 TEST_F(NotificationPlatformBridgeLinuxTest, NotificationListItemsInBody) {
284 EXPECT_CALL(*mock_notification_proxy_.get(),
285 MockCallMethodAndBlock(Calls("Notify"), _))
286 .WillOnce(OnNotify(
287 [](const NotificationRequest& request) {
288 EXPECT_EQ("abc - 123\ndef - 456", request.body);
289 },
290 1));
291
292 CreateNotificationBridgeLinux();
293 notification_bridge_linux_->Display(
294 NotificationCommon::PERSISTENT, "", "", false,
295 NotificationBuilder("")
296 .SetType(message_center::NOTIFICATION_TYPE_MULTIPLE)
297 .SetItems(std::vector<message_center::NotificationItem>{
298 {base::UTF8ToUTF16("abc"), base::UTF8ToUTF16("123")},
299 {base::UTF8ToUTF16("def"), base::UTF8ToUTF16("456")}})
300 .GetResult());
301 }
OLDNEW
« no previous file with comments | « chrome/browser/notifications/notification_platform_bridge_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698