diff options
author | Florian Bruhin <me@the-compiler.org> | 2021-03-26 14:24:27 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2021-03-27 15:30:02 +0100 |
commit | 0754bc2d901087ffdd4611bd60bffa814851564c (patch) | |
tree | d3853ad716bdfa945c9896cdd5e786decae060d5 /tests/end2end | |
parent | 9cda31f7f6a4537ffdaca6aaa88d19bfd3295ea4 (diff) | |
download | qutebrowser-0754bc2d901087ffdd4611bd60bffa814851564c.tar.gz qutebrowser-0754bc2d901087ffdd4611bd60bffa814851564c.zip |
notifications: Verify image dimensions in tests
Diffstat (limited to 'tests/end2end')
-rw-r--r-- | tests/end2end/features/notifications.feature | 5 | ||||
-rw-r--r-- | tests/end2end/features/test_notifications_bdd.py | 7 | ||||
-rw-r--r-- | tests/end2end/fixtures/notificationserver.py | 19 |
3 files changed, 25 insertions, 6 deletions
diff --git a/tests/end2end/features/notifications.feature b/tests/end2end/features/notifications.feature index 6cc94180f..6e4e7bab9 100644 --- a/tests/end2end/features/notifications.feature +++ b/tests/end2end/features/notifications.feature @@ -12,6 +12,7 @@ Feature: Notifications 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 Scenario: Notification containing escaped characters Given the notification server supports body markup @@ -31,21 +32,25 @@ Feature: Notifications 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 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 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 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 # 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 diff --git a/tests/end2end/features/test_notifications_bdd.py b/tests/end2end/features/test_notifications_bdd.py index 2dd99eed0..039239900 100644 --- a/tests/end2end/features/test_notifications_bdd.py +++ b/tests/end2end/features/test_notifications_bdd.py @@ -80,6 +80,13 @@ def notification_title(notification_server, id_, title): assert notification_server.messages[id_].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_] + assert (msg.img_width, msg.img_height) == (width, height) + + @bdd.when(bdd.parsers.cfparse('I close the notification with id {id_:d}')) def close_notification(notification_server, id_): notification_server.close(id_) diff --git a/tests/end2end/fixtures/notificationserver.py b/tests/end2end/fixtures/notificationserver.py index ecfac1842..0ee77767f 100644 --- a/tests/end2end/fixtures/notificationserver.py +++ b/tests/end2end/fixtures/notificationserver.py @@ -19,7 +19,7 @@ import dataclasses import itertools -from typing import Dict, List +from typing import Dict, List, Tuple from PyQt5.QtCore import QObject, QVariant, QByteArray, pyqtSlot from PyQt5.QtGui import QImage @@ -37,6 +37,8 @@ class NotificationProperties: title: str body: str replaces_id: int + img_width: int + img_height: int def _as_uint32(x: int) -> QVariant: @@ -102,14 +104,15 @@ class TestNotificationServer(QObject): assert hints['x-qutebrowser-origin'].startswith('http://localhost:') assert hints['desktop-entry'] == 'org.qutebrowser.qutebrowser' - self._validate_image(*hints["image-data"]) + img = self._parse_image(*hints["image-data"]) if replaces_id != 0: assert replaces_id in self.messages - return NotificationProperties(title=title, body=body, replaces_id=replaces_id) + return NotificationProperties(title=title, body=body, replaces_id=replaces_id, + img_width=img.width(), img_height=img.height()) - def _validate_image( + def _parse_image( self, width: int, height: int, @@ -118,8 +121,8 @@ class TestNotificationServer(QObject): bits_per_color: int, channel_count: int, data: QByteArray, - ) -> None: - """Make sure the given image data is valid.""" + ) -> QImage: + """Make sure the given image data is valid and return a QImage.""" # Chromium limit? assert 0 < width <= 320 assert 0 < height <= 320 @@ -138,6 +141,10 @@ class TestNotificationServer(QObject): qimage_format = QImage.Format_RGBA8888 if has_alpha else QImage.Format_RGB888 img = QImage(data, width, height, bytes_per_line, qimage_format) assert not img.isNull() + assert img.width() == width + assert img.height() == height + + return img def close(self, notification_id: int) -> None: """Sends a close notification for the given ID.""" |