notifications: Fix and test support for PyQtWebEngine 5.14
This commit is contained in:
parent
54a0dc1e38
commit
844435f821
|
|
@ -156,16 +156,10 @@ class DBusNotificationPresenter(QObject):
|
|||
# WORKAROUND for
|
||||
# https://www.riverbankcomputing.com/pipermail/pyqt/2020-May/042916.html
|
||||
# Fixed in PyQtWebEngine 5.15.0
|
||||
|
||||
try:
|
||||
from PyQt5.QtWebEngine import PYQT_WEBENGINE_VERSION
|
||||
except ImportError:
|
||||
# Added with PyQtWebEngine 5.13
|
||||
needs_workaround = True
|
||||
else:
|
||||
needs_workaround = PYQT_WEBENGINE_VERSION < 0x050F00
|
||||
|
||||
if needs_workaround:
|
||||
# PYQT_WEBENGINE_VERSION was added with PyQtWebEngine 5.13, but if we're here,
|
||||
# we already did a version check above.
|
||||
from PyQt5.QtWebEngine import PYQT_WEBENGINE_VERSION
|
||||
if PYQT_WEBENGINE_VERSION < 0x050F00:
|
||||
# PyQtWebEngine unrefs the callback after it's called, for some
|
||||
# reason. So we call setNotificationPresenter again to *increase*
|
||||
# its refcount to prevent it from getting GC'd. Otherwise, random
|
||||
|
|
@ -218,9 +212,18 @@ class DBusNotificationPresenter(QObject):
|
|||
"""
|
||||
if not new_notification.tag():
|
||||
return 0
|
||||
for notification_id, notification in self._active_notifications.items():
|
||||
if notification.matches(new_notification):
|
||||
return notification_id
|
||||
|
||||
try:
|
||||
for notification_id, notification in self._active_notifications.items():
|
||||
if notification.matches(new_notification):
|
||||
return notification_id
|
||||
except RuntimeError:
|
||||
# WORKAROUND for
|
||||
# https://www.riverbankcomputing.com/pipermail/pyqt/2020-May/042918.html
|
||||
# (also affects .matches)
|
||||
log.misc.debug(
|
||||
f"Ignoring notification tag {new_notification.tag()!r} due to PyQt bug")
|
||||
|
||||
return 0
|
||||
|
||||
def _present(self, qt_notification: "QWebEngineNotification") -> None:
|
||||
|
|
@ -316,13 +319,15 @@ class DBusNotificationPresenter(QObject):
|
|||
|
||||
notification_id, _close_reason = msg.arguments()
|
||||
notification = self._active_notifications.get(notification_id)
|
||||
|
||||
if notification is not None:
|
||||
try:
|
||||
notification.close()
|
||||
except RuntimeError:
|
||||
# WORKAROUND for
|
||||
# https://www.riverbankcomputing.com/pipermail/pyqt/2020-May/042918.html
|
||||
pass
|
||||
log.misc.debug("Ignoring close request for notification "
|
||||
f"{notification_id} due to PyQt bug")
|
||||
|
||||
@pyqtSlot(QDBusMessage)
|
||||
def _handle_action(self, msg: QDBusMessage) -> None:
|
||||
|
|
@ -339,7 +344,8 @@ class DBusNotificationPresenter(QObject):
|
|||
except RuntimeError:
|
||||
# WORKAROUND for
|
||||
# https://www.riverbankcomputing.com/pipermail/pyqt/2020-May/042918.html
|
||||
pass
|
||||
log.misc.debug("Ignoring click request for notification "
|
||||
f"{notification_id} due to PyQt bug")
|
||||
|
||||
def _fetch_capabilities(self) -> None:
|
||||
"""Fetch capabilities from the notification server."""
|
||||
|
|
|
|||
|
|
@ -14,15 +14,6 @@ Feature: Notifications
|
|||
Then the javascript message "notification shown" should be logged
|
||||
And a notification with id 1 is presented
|
||||
|
||||
@qtwebengine_notifications
|
||||
Scenario: Replacing existing notifications
|
||||
When I run :click-element id show-multiple-button
|
||||
Then the javascript message "i=1 notification shown" should be logged
|
||||
Then the javascript message "i=2 notification shown" should be logged
|
||||
Then the javascript message "i=3 notification shown" should be logged
|
||||
And 1 notification is presented
|
||||
And notification 1 has title "i=3"
|
||||
|
||||
@qtwebengine_notifications
|
||||
Scenario: Notification containing escaped characters
|
||||
Given the notification server supports body markup
|
||||
|
|
@ -39,12 +30,35 @@ Feature: Notifications
|
|||
And notification 1 has body "<< && >>"
|
||||
And notification 1 has title "<< && >>"
|
||||
|
||||
# As a WORKAROUND for https://www.riverbankcomputing.com/pipermail/pyqt/2020-May/042918.html
|
||||
# and other issues, those can only run with PyQtWebEngine >= 5.15.0
|
||||
#
|
||||
# For these tests, we need to wait for the notification to be shown before
|
||||
# we try to close it, otherwise we wind up in race-condition-ish
|
||||
# situations.
|
||||
|
||||
# As a WORKAROUND for https://www.riverbankcomputing.com/pipermail/pyqt/2020-May/042918.html
|
||||
# and other issues, those can only run with PyQtWebEngine >= 5.15.0
|
||||
@qtwebengine_notifications @pyqtwebengine>=5.15.0
|
||||
Scenario: Replacing existing notifications
|
||||
When I run :click-element id show-multiple-button
|
||||
Then the javascript message "i=1 notification shown" should be logged
|
||||
Then the javascript message "i=2 notification shown" should be logged
|
||||
Then the javascript message "i=3 notification shown" should be logged
|
||||
And 1 notification is presented
|
||||
And notification 1 has title "i=3"
|
||||
|
||||
@qtwebengine_notifications @pyqtwebengine<5.15.0
|
||||
Scenario: Replacing existing notifications (old Qt)
|
||||
When I run :click-element id show-multiple-button
|
||||
Then the javascript message "i=1 notification shown" should be logged
|
||||
And "Ignoring notification tag 'counter' due to PyQt bug" should be logged
|
||||
And the javascript message "i=2 notification shown" should be logged
|
||||
And "Ignoring notification tag 'counter' due to PyQt bug" should be logged
|
||||
And the javascript message "i=3 notification shown" should be logged
|
||||
And "Ignoring notification tag 'counter' due to PyQt bug" should be logged
|
||||
And 3 notifications are presented
|
||||
And notification 1 has title "i=1"
|
||||
And notification 2 has title "i=2"
|
||||
And notification 3 has title "i=3"
|
||||
|
||||
@qtwebengine_notifications @pyqtwebengine>=5.15.0
|
||||
Scenario: User closes presented notification
|
||||
|
|
@ -53,6 +67,15 @@ Feature: Notifications
|
|||
And I close the notification with id 1
|
||||
Then the javascript message "notification closed" should be logged
|
||||
|
||||
@qtwebengine_notifications @pyqtwebengine<5.15.0
|
||||
Scenario: User closes presented notification (old Qt)
|
||||
When I run :click-element id show-button
|
||||
And I wait for the javascript message "notification shown"
|
||||
And I close the notification with id 1
|
||||
Then "Ignoring close request for notification 1 due to PyQt bug" should be logged
|
||||
And the javascript message "notification closed" should not be logged
|
||||
And no crash should happen
|
||||
|
||||
@qtwebengine_notifications @pyqtwebengine>=5.15.0
|
||||
Scenario: User closes some other application's notification
|
||||
When I run :click-element id show-button
|
||||
|
|
@ -67,6 +90,15 @@ Feature: Notifications
|
|||
And I click the notification with id 1
|
||||
Then the javascript message "notification clicked" should be logged
|
||||
|
||||
@qtwebengine_notifications @pyqtwebengine<5.15.0
|
||||
Scenario: User clicks presented notification (old Qt)
|
||||
When I run :click-element id show-button
|
||||
And I wait for the javascript message "notification shown"
|
||||
And I click the notification with id 1
|
||||
Then "Ignoring click request for notification 1 due to PyQt bug" should be logged
|
||||
Then the javascript message "notification clicked" should not be logged
|
||||
And no crash should happen
|
||||
|
||||
@qtwebengine_notifications @pyqtwebengine>=5.15.0
|
||||
Scenario: User clicks some other application's notification
|
||||
When I run :click-element id show-button
|
||||
|
|
|
|||
|
|
@ -54,6 +54,11 @@ def notification_presented_single(notification_server):
|
|||
assert len(notification_server.messages) == 1
|
||||
|
||||
|
||||
@bdd.then(bdd.parsers.cfparse('{count:d} notifications are presented'))
|
||||
def notification_presented_count(notification_server, count):
|
||||
assert len(notification_server.messages) == count
|
||||
|
||||
|
||||
@bdd.then(bdd.parsers.cfparse('notification {id_:d} has body "{body}"'))
|
||||
def notification_body(notification_server, id_, body):
|
||||
assert notification_server.messages[id_].body == body
|
||||
|
|
|
|||
Loading…
Reference in New Issue