summaryrefslogtreecommitdiff
path: root/tests/end2end
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2021-03-26 19:13:30 +0100
committerFlorian Bruhin <me@the-compiler.org>2021-03-27 15:30:57 +0100
commit38dee6b22559eefbccc5bccd8cdccffc3dd30dac (patch)
treecb02b42411fae31a66da493bce7f25f2a2843412 /tests/end2end
parent9eb009dc1b30243a7c60b5fee3df8435184897fc (diff)
downloadqutebrowser-38dee6b22559eefbccc5bccd8cdccffc3dd30dac.tar.gz
qutebrowser-38dee6b22559eefbccc5bccd8cdccffc3dd30dac.zip
notifications: Update tests for increasing IDs
This is a bit of a bigger change (and makes the tests a bit less strict), but it's needed because qutebrowser assumes that IDs will be unique (i.e. it'll never get a notification ID which is equal to the ID for a notification being shown). This means we'll need to keep the notification server around and clean up notifications between tests.
Diffstat (limited to 'tests/end2end')
-rw-r--r--tests/end2end/features/notifications.feature51
-rw-r--r--tests/end2end/features/test_notifications_bdd.py46
-rw-r--r--tests/end2end/fixtures/notificationserver.py12
3 files changed, 63 insertions, 46 deletions
diff --git a/tests/end2end/features/notifications.feature b/tests/end2end/features/notifications.feature
index 21ba110d4..b797f08d7 100644
--- a/tests/end2end/features/notifications.feature
+++ b/tests/end2end/features/notifications.feature
@@ -4,59 +4,60 @@ Feature: Notifications
HTML5 notification API interaction
Background:
- When I open data/javascript/notifications.html
+ Given I open data/javascript/notifications.html
And I set content.notifications.enabled to true
And I run :click-element id button
+ And I clean up the notification server
Scenario: Notification is shown
When I run :click-element id show-button
Then the javascript message "notification shown" should be logged
- And a notification with id 1 should be presented
- And notification 1 should have image dimensions 64x64 # qutebrowser logo
+ And 1 notification should be presented
+ And the notification should have image dimensions 64x64 # qutebrowser logo
Scenario: Notification containing escaped characters
Given the notification server supports body markup
When I run :click-element id show-symbols-button
Then the javascript message "notification shown" should be logged
- And notification 1 should have body "&lt;&lt; &amp;&amp; &gt;&gt;"
- And notification 1 should have title "<< && >>"
+ And the notification should have body "&lt;&lt; &amp;&amp; &gt;&gt;"
+ And the notification should have title "<< && >>"
Scenario: Notification containing escaped characters with no body markup
Given the notification server doesn't support body markup
When I run :click-element id show-symbols-button
Then the javascript message "notification shown" should be logged
- And notification 1 should have body "<< && >>"
- And notification 1 should have title "<< && >>"
+ And the notification should have body "<< && >>"
+ And the notification should have title "<< && >>"
Scenario: Notification with RGB image
When I run :click-element id show-image-button-noalpha
Then the javascript message "notification shown" should be logged
- And notification 1 should have title "RGB"
- And notification 1 should have image dimensions 64x64
+ And the notification should have title "RGB"
+ And the notification should have image dimensions 64x64
Scenario: Notification with RGBA image
When I run :click-element id show-image-button
Then the javascript message "notification shown" should be logged
- And notification 1 should have title "RGBA"
- And notification 1 should have image dimensions 64x64
+ And the notification should have title "RGBA"
+ And the notification should have image dimensions 64x64
Scenario: Notification with big image
When I run :click-element id show-image-button-big
Then the javascript message "notification shown" should be logged
- And notification 1 should have title "Big"
- And notification 1 should have image dimensions 320x160
+ And the notification should have title "Big"
+ And the notification should have image dimensions 320x160
Scenario: Notification with padded image
When I run :click-element id show-image-button-padded
Then the javascript message "notification shown" should be logged
- And notification 1 should have title "Padded"
- And notification 1 should have image dimensions 46x46
+ And the notification should have title "Padded"
+ And the notification should have image dimensions 46x46
Scenario: Closing notification via web
When I run :click-element id show-closing-button
Then the javascript message "notification shown" should be logged
And the javascript message "notification closed" should be logged
- And notification 1 should be closed via web
+ And the notification should be closed via web
# 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
@@ -72,7 +73,7 @@ Feature: Notifications
And the javascript message "i=2 notification shown" should be logged
And the javascript message "i=3 notification shown" should be logged
And 1 notification should be presented
- And notification 1 should have title "i=3"
+ And the notification should have title "i=3"
@pyqtwebengine<5.15.0
Scenario: Replacing existing notifications (old Qt)
@@ -84,23 +85,21 @@ Feature: Notifications
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 should be presented
- And notification 1 should have title "i=1"
- And notification 2 should have title "i=2"
- And notification 3 should have title "i=3"
+ And the notification should have title "i=3" # last one
@pyqtwebengine>=5.15.0
Scenario: User closes presented notification
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
+ And I close the notification
Then the javascript message "notification closed" should be logged
@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 I close the notification
+ Then "Ignoring close request for notification * due to PyQt bug" should be logged
And the javascript message "notification closed" should not be logged
And no crash should happen
@@ -115,15 +114,15 @@ Feature: Notifications
Scenario: User clicks presented notification
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
+ And I click the notification
Then the javascript message "notification clicked" should be logged
@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
+ And I click the notification
+ Then "Ignoring click request for notification * due to PyQt bug" should be logged
Then the javascript message "notification clicked" should not be logged
And no crash should happen
diff --git a/tests/end2end/features/test_notifications_bdd.py b/tests/end2end/features/test_notifications_bdd.py
index 5b16c1fc5..15a123be3 100644
--- a/tests/end2end/features/test_notifications_bdd.py
+++ b/tests/end2end/features/test_notifications_bdd.py
@@ -52,9 +52,9 @@ def doesnt_support_body_markup(notification_server, quteproc):
"bridge._drop_adapter()")
-@bdd.then(bdd.parsers.cfparse('a notification with id {id_:d} should be presented'))
-def notification_presented(notification_server, id_):
- assert id_ in notification_server.messages
+@bdd.given('I clean up the notification server')
+def cleanup_notification_server(notification_server):
+ notification_server.cleanup()
@bdd.then('1 notification should be presented')
@@ -67,36 +67,48 @@ def notification_presented_count(notification_server, count):
assert len(notification_server.messages) == count
-@bdd.then(bdd.parsers.cfparse('notification {id_:d} should have body "{body}"'))
-def notification_body(notification_server, id_, body):
- assert notification_server.messages[id_].body == body
+@bdd.then(bdd.parsers.parse('the notification should have body "{body}"'))
+def notification_body(notification_server, body):
+ msg = notification_server.last_msg()
+ assert msg.body == body
-@bdd.then(bdd.parsers.cfparse('notification {id_:d} should have title "{title}"'))
-def notification_title(notification_server, id_, title):
- assert notification_server.messages[id_].title == title
+@bdd.then(bdd.parsers.parse('the notification should have title "{title}"'))
+def notification_title(notification_server, title):
+ msg = notification_server.last_msg()
+ assert msg.title == title
@bdd.then(bdd.parsers.cfparse(
- 'notification {id_:d} should have image dimensions {width:d}x{height:d}'))
-def notification_image_dimensions(notification_server, id_, width, height):
- msg = notification_server.messages[id_]
+ 'the notification should have image dimensions {width:d}x{height:d}'))
+def notification_image_dimensions(notification_server, width, height):
+ msg = notification_server.last_msg()
assert (msg.img_width, msg.img_height) == (width, height)
-@bdd.then(bdd.parsers.cfparse('notification {id_:d} should be closed via web'))
-def notification_closed(notification_server, id_):
- msg = notification_server.messages[id_]
+@bdd.then('the notification should be closed via web')
+def notification_closed(notification_server):
+ msg = notification_server.last_msg()
assert msg.closed_via_web
+@bdd.when('I close the notification')
+def close_notification(notification_server):
+ notification_server.close(notification_server.last_id)
+
+
@bdd.when(bdd.parsers.cfparse('I close the notification with id {id_:d}'))
-def close_notification(notification_server, id_):
+def close_notification_id(notification_server, id_):
notification_server.close(id_)
+@bdd.when('I click the notification')
+def click_notification(notification_server):
+ notification_server.click(notification_server.last_id)
+
+
@bdd.when(bdd.parsers.cfparse('I click the notification with id {id_:d}'))
-def click_notification(notification_server, id_):
+def click_notification_id(notification_server, id_):
notification_server.click(id_)
diff --git a/tests/end2end/fixtures/notificationserver.py b/tests/end2end/fixtures/notificationserver.py
index f956ed948..4264abe09 100644
--- a/tests/end2end/fixtures/notificationserver.py
+++ b/tests/end2end/fixtures/notificationserver.py
@@ -42,8 +42,6 @@ class NotificationProperties:
closed_via_web: bool = False
-
-
class TestNotificationServer(QObject):
"""A libnotify notification server used for testing."""
@@ -62,6 +60,13 @@ class TestNotificationServer(QObject):
# A dict mapping notification IDs to currently-displayed notifications.
self.messages: Dict[int, NotificationProperties] = {}
self.supports_body_markup = True
+ self.last_id = None
+
+ def cleanup(self) -> None:
+ self.messages = {}
+
+ def last_msg(self) -> NotificationProperties:
+ return self.messages[self.last_id]
def register(self) -> bool:
"""Try to register to DBus.
@@ -190,6 +195,7 @@ class TestNotificationServer(QObject):
message_id = message.replaces_id
self.messages[message_id] = message
+ self.last_id = message_id
return message_id
@pyqtSlot(QDBusMessage, result="QStringList")
@@ -212,7 +218,7 @@ class TestNotificationServer(QObject):
self.messages[message_id].closed_via_web = True
-@pytest.fixture
+@pytest.fixture(scope='module')
def notification_server(qapp):
if utils.is_windows:
# The QDBusConnection destructor seems to cause error messages (and potentially