notifications: Fix handling of custom actions on foreign notifications

This commit is contained in:
Florian Bruhin 2021-03-25 15:20:40 +01:00
parent a21adf8bd3
commit 384928c378
4 changed files with 21 additions and 4 deletions

View File

@ -334,11 +334,11 @@ class DBusNotificationPresenter(QObject):
self._verify_message(msg, "us", QDBusMessage.SignalMessage)
notification_id, action_key = msg.arguments()
if action_key != "default":
raise Error(f"Got unknown action {action_key}")
notification = self._active_notifications.get(notification_id)
if notification is not None:
if action_key != "default":
raise Error(f"Got unknown action {action_key}")
try:
notification.click()
except RuntimeError:

View File

@ -105,3 +105,10 @@ Feature: Notifications
And I wait for the javascript message "notification shown"
And I click the notification with id 1234
Then the javascript message "notification clicked" should not be logged
@qtwebengine_notifications @pyqtwebengine>=5.15.0
Scenario: Unknown action with some other application's notification
When I run :click-element id show-button
And I wait for the javascript message "notification shown"
And I trigger a custom action on the notification with id 1234
Then no crash should happen

View File

@ -77,3 +77,9 @@ def close_notification(notification_server, id_):
@bdd.when(bdd.parsers.cfparse('I click the notification with id {id_:d}'))
def click_notification(notification_server, id_):
notification_server.click(id_)
@bdd.when(bdd.parsers.cfparse(
'I trigger a {name} action on the notification with id {id_:d}'))
def custom_notification_action(notification_server, id_, name):
notification_server.action(id_, name)

View File

@ -121,14 +121,18 @@ class TestNotificationServer(QObject):
def click(self, notification_id: int) -> None:
"""Sends a click (default action) notification for the given ID."""
self.action(notification_id, "default")
def action(self, notification_id: int, name: str) -> None:
"""Sends an action notification for the given ID."""
message = QDBusMessage.createSignal(
notification.DBusNotificationPresenter.PATH,
notification.DBusNotificationPresenter.INTERFACE,
"ActionInvoked")
message.setArguments([_as_uint32(notification_id), "default"])
message.setArguments([_as_uint32(notification_id), name])
if not self._bus.send(message):
raise OSError("Could not send click notification")
raise OSError("Could not send action notification")
# Everything below is exposed via DBus
# pylint: disable=invalid-name