diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index cf307c93c..db9c4e4b9 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -76,7 +76,8 @@ def init(): from qutebrowser.browser.webengine import notification log.init.debug("Setting up DBus notification presenter...") try: - presenter = notification.DBusNotificationPresenter() + testing = 'test-notification-service' in objects.debug_flags + presenter = notification.DBusNotificationPresenter(testing) for p in [webenginesettings.default_profile, webenginesettings.private_profile]: if not p: continue diff --git a/qutebrowser/qutebrowser.py b/qutebrowser/qutebrowser.py index 0ffdb5567..327388e75 100644 --- a/qutebrowser/qutebrowser.py +++ b/qutebrowser/qutebrowser.py @@ -172,11 +172,12 @@ def debug_flag_error(flag): stack: Enable Chromium stack logging. chromium: Enable Chromium logging. werror: Turn Python warnings into errors. + test-notification-service: Use the testing libnotify service. """ valid_flags = ['debug-exit', 'pdb-postmortem', 'no-sql-history', 'no-scroll-filtering', 'log-requests', 'log-cookies', 'lost-focusproxy', 'log-scroll-pos', 'stack', 'chromium', - 'werror'] + 'werror', 'test-notification-service'] if flag in valid_flags: return flag diff --git a/tests/end2end/conftest.py b/tests/end2end/conftest.py index 273d8170c..7190c7ef4 100644 --- a/tests/end2end/conftest.py +++ b/tests/end2end/conftest.py @@ -34,6 +34,7 @@ from PyQt5.QtCore import PYQT_VERSION pytest.register_assert_rewrite('end2end.fixtures') +from end2end.fixtures.notificationserver import notification_server from end2end.fixtures.webserver import server, server_per_test, ssl_server from end2end.fixtures.quteprocess import (quteproc_process, quteproc, quteproc_new) diff --git a/tests/end2end/fixtures/notificationserver.py b/tests/end2end/fixtures/notificationserver.py index a1e74753d..9ef7cb77b 100644 --- a/tests/end2end/fixtures/notificationserver.py +++ b/tests/end2end/fixtures/notificationserver.py @@ -21,24 +21,28 @@ class TestNotificationServer(QObject): def __init__(self, service: str): # Note that external users should call get() instead. super().__init__() - self.service = service - self.bus = QDBusConnection.sessionBus() + self._service = service + self._bus = QDBusConnection.sessionBus() + self._message_id = 0 + # A list of all the messages that we've received. Test code should + # inspect this to make sure messages get delivered. self.messages = [] # type: typing.List[QDBusMessage] def register(self) -> None: - assert self.bus.registerService(self.service) - assert self.registerObject(DBusNotificationPresenter.PATH, + assert self._bus.registerService(self._service) + assert self._bus.registerObject(DBusNotificationPresenter.PATH, DBusNotificationPresenter.INTERFACE, self, QDBusConnection.ExportAllSlots) def unregister(self) -> None: - assert self.bus.unregisterService(self.service) - self.messages = [] + assert self._bus.unregisterService(self._service) - @pyqtSlot(QDBusMessage) - def Notify(self, message: QDBusMessage) -> None: + @pyqtSlot(QDBusMessage, result="uint") + def Notify(self, message: QDBusMessage) -> QDBusArgument: + self._message_id += 1 self.messages.append(message) + return self._message_id def close(self, notification_id: int) -> None: """Sends a close notification for the given ID.""" @@ -46,8 +50,10 @@ class TestNotificationServer(QObject): DBusNotificationPresenter.PATH, DBusNotificationPresenter.INTERFACE, "NotificationClosed") + # the 2 here is the notification removal reason; it's effectively + # arbitrary message.setArguments([_as_uint32(notification_id), _as_uint32(2)]) - if not self.bus.send(message): + if not self._bus.send(message): raise IOError("Could not send close notification") @pytest.fixture @@ -60,6 +66,6 @@ def notification_server(qapp): def _as_uint32(x: int) -> QVariant: variant = QVariant(x) - variant.convert(QVariant.UInt) + assert variant.convert(QVariant.UInt) return variant diff --git a/tests/end2end/fixtures/quteprocess.py b/tests/end2end/fixtures/quteprocess.py index 5f8263334..a8af02d19 100644 --- a/tests/end2end/fixtures/quteprocess.py +++ b/tests/end2end/fixtures/quteprocess.py @@ -526,7 +526,8 @@ class QuteProc(testprocess.Process): args = ['--debug', '--no-err-windows', '--temp-basedir', '--json-logging', '--loglevel', 'vdebug', '--backend', backend, '--debug-flag', 'no-sql-history', - '--debug-flag', 'werror'] + '--debug-flag', 'werror', '--debug-flag', + 'test-notification-service'] if qVersion() == '5.7.1': # https://github.com/qutebrowser/qutebrowser/issues/3163 args += ['--qt-flag', 'disable-seccomp-filter-sandbox'] @@ -983,7 +984,7 @@ def quteproc_process(qapp, server, request): @pytest.fixture -def quteproc(quteproc_process, server, request): +def quteproc(quteproc_process, server, request, notification_server): """Per-test qutebrowser fixture which uses the per-file process.""" request.node._quteproc_log = quteproc_process.captured_log quteproc_process.before_test()