OLD | NEW |
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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( | 50 NotificationBuilder& SetItems( |
51 const std::vector<message_center::NotificationItem>& items) { | 51 const std::vector<message_center::NotificationItem>& items) { |
52 notification_.set_items(items); | 52 notification_.set_items(items); |
53 return *this; | 53 return *this; |
54 } | 54 } |
55 | 55 |
| 56 NotificationBuilder& SetNeverTimeout(bool never_timeout) { |
| 57 notification_.set_never_timeout(never_timeout); |
| 58 return *this; |
| 59 } |
| 60 |
56 NotificationBuilder& SetProgress(int progress) { | 61 NotificationBuilder& SetProgress(int progress) { |
57 notification_.set_progress(progress); | 62 notification_.set_progress(progress); |
58 return *this; | 63 return *this; |
59 } | 64 } |
60 | 65 |
61 NotificationBuilder& SetTitle(const base::string16& title) { | 66 NotificationBuilder& SetTitle(const base::string16& title) { |
62 notification_.set_title(title); | 67 notification_.set_title(title); |
63 return *this; | 68 return *this; |
64 } | 69 } |
65 | 70 |
66 NotificationBuilder& SetType(message_center::NotificationType type) { | 71 NotificationBuilder& SetType(message_center::NotificationType type) { |
67 notification_.set_type(type); | 72 notification_.set_type(type); |
68 return *this; | 73 return *this; |
69 } | 74 } |
70 | 75 |
71 private: | 76 private: |
72 Notification notification_; | 77 Notification notification_; |
73 }; | 78 }; |
74 | 79 |
75 struct NotificationRequest { | 80 struct NotificationRequest { |
76 std::string summary; | 81 std::string summary; |
77 std::string body; | 82 std::string body; |
| 83 int32_t expire_timeout = 0; |
78 }; | 84 }; |
79 | 85 |
80 NotificationRequest ParseRequest(dbus::MethodCall* method_call) { | 86 NotificationRequest ParseRequest(dbus::MethodCall* method_call) { |
81 // The "Notify" message must have type (susssasa{sv}i). | 87 // The "Notify" message must have type (susssasa{sv}i). |
82 // https://developer.gnome.org/notification-spec/#command-notify | 88 // https://developer.gnome.org/notification-spec/#command-notify |
83 NotificationRequest request; | 89 NotificationRequest request; |
84 | 90 |
85 dbus::MessageReader reader(method_call); | 91 dbus::MessageReader reader(method_call); |
86 std::string str; | 92 std::string str; |
87 uint32_t uint32; | 93 uint32_t uint32; |
88 int32_t int32; | |
89 EXPECT_TRUE(reader.PopString(&str)); // app_name | 94 EXPECT_TRUE(reader.PopString(&str)); // app_name |
90 EXPECT_TRUE(reader.PopUint32(&uint32)); // replaces_id | 95 EXPECT_TRUE(reader.PopUint32(&uint32)); // replaces_id |
91 EXPECT_TRUE(reader.PopString(&str)); // app_icon | 96 EXPECT_TRUE(reader.PopString(&str)); // app_icon |
92 EXPECT_TRUE(reader.PopString(&request.summary)); // summary | 97 EXPECT_TRUE(reader.PopString(&request.summary)); // summary |
93 EXPECT_TRUE(reader.PopString(&request.body)); // body | 98 EXPECT_TRUE(reader.PopString(&request.body)); // body |
94 | 99 |
95 { | 100 { |
96 dbus::MessageReader actions_reader(nullptr); | 101 dbus::MessageReader actions_reader(nullptr); |
97 EXPECT_TRUE(reader.PopArray(&actions_reader)); | 102 EXPECT_TRUE(reader.PopArray(&actions_reader)); |
98 while (actions_reader.HasMoreData()) { | 103 while (actions_reader.HasMoreData()) { |
99 // Actions come in pairs. | 104 // Actions come in pairs. |
100 EXPECT_TRUE(actions_reader.PopString(&str)); | 105 EXPECT_TRUE(actions_reader.PopString(&str)); |
101 EXPECT_TRUE(actions_reader.PopString(&str)); | 106 EXPECT_TRUE(actions_reader.PopString(&str)); |
102 } | 107 } |
103 } | 108 } |
104 | 109 |
105 { | 110 { |
106 dbus::MessageReader hints_reader(nullptr); | 111 dbus::MessageReader hints_reader(nullptr); |
107 EXPECT_TRUE(reader.PopArray(&hints_reader)); | 112 EXPECT_TRUE(reader.PopArray(&hints_reader)); |
108 while (hints_reader.HasMoreData()) { | 113 while (hints_reader.HasMoreData()) { |
109 dbus::MessageReader dict_entry_reader(nullptr); | 114 dbus::MessageReader dict_entry_reader(nullptr); |
110 EXPECT_TRUE(hints_reader.PopDictEntry(&dict_entry_reader)); | 115 EXPECT_TRUE(hints_reader.PopDictEntry(&dict_entry_reader)); |
111 EXPECT_TRUE(dict_entry_reader.PopString(&str)); | 116 EXPECT_TRUE(dict_entry_reader.PopString(&str)); |
112 dbus::MessageReader variant_reader(nullptr); | 117 dbus::MessageReader variant_reader(nullptr); |
113 EXPECT_TRUE(dict_entry_reader.PopVariant(&variant_reader)); | 118 EXPECT_TRUE(dict_entry_reader.PopVariant(&variant_reader)); |
114 EXPECT_FALSE(dict_entry_reader.HasMoreData()); | 119 EXPECT_FALSE(dict_entry_reader.HasMoreData()); |
115 } | 120 } |
116 } | 121 } |
117 | 122 |
118 EXPECT_TRUE(reader.PopInt32(&int32)); // expire_timeout | 123 EXPECT_TRUE(reader.PopInt32(&request.expire_timeout)); |
119 EXPECT_FALSE(reader.HasMoreData()); | 124 EXPECT_FALSE(reader.HasMoreData()); |
120 | 125 |
121 return request; | 126 return request; |
122 } | 127 } |
123 | 128 |
124 dbus::Response* GetIdResponse(uint32_t id) { | 129 dbus::Response* GetIdResponse(uint32_t id) { |
125 dbus::Response* response = dbus::Response::CreateEmpty().release(); | 130 dbus::Response* response = dbus::Response::CreateEmpty().release(); |
126 dbus::MessageWriter writer(response); | 131 dbus::MessageWriter writer(response); |
127 writer.AppendUint32(id); | 132 writer.AppendUint32(id); |
128 return response; | 133 return response; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 CreateNotificationBridgeLinux(); | 297 CreateNotificationBridgeLinux(); |
293 notification_bridge_linux_->Display( | 298 notification_bridge_linux_->Display( |
294 NotificationCommon::PERSISTENT, "", "", false, | 299 NotificationCommon::PERSISTENT, "", "", false, |
295 NotificationBuilder("") | 300 NotificationBuilder("") |
296 .SetType(message_center::NOTIFICATION_TYPE_MULTIPLE) | 301 .SetType(message_center::NOTIFICATION_TYPE_MULTIPLE) |
297 .SetItems(std::vector<message_center::NotificationItem>{ | 302 .SetItems(std::vector<message_center::NotificationItem>{ |
298 {base::UTF8ToUTF16("abc"), base::UTF8ToUTF16("123")}, | 303 {base::UTF8ToUTF16("abc"), base::UTF8ToUTF16("123")}, |
299 {base::UTF8ToUTF16("def"), base::UTF8ToUTF16("456")}}) | 304 {base::UTF8ToUTF16("def"), base::UTF8ToUTF16("456")}}) |
300 .GetResult()); | 305 .GetResult()); |
301 } | 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 } |
OLD | NEW |