summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2021-03-26 14:17:22 +0100
committerFlorian Bruhin <me@the-compiler.org>2021-03-27 15:30:02 +0100
commit9cda31f7f6a4537ffdaca6aaa88d19bfd3295ea4 (patch)
tree5e4538c5de128a39821803e7ec5293e325189718 /tests
parentd1e9247536e413c444a10023df1235ac31065044 (diff)
downloadqutebrowser-9cda31f7f6a4537ffdaca6aaa88d19bfd3295ea4.tar.gz
qutebrowser-9cda31f7f6a4537ffdaca6aaa88d19bfd3295ea4.zip
notifications: Fix handling of padded images
Diffstat (limited to 'tests')
-rw-r--r--tests/end2end/data/javascript/img/big.pngbin0 -> 2796 bytes
-rw-r--r--tests/end2end/data/javascript/img/padded.pngbin0 -> 5617 bytes
-rw-r--r--tests/end2end/data/javascript/notifications.html17
-rw-r--r--tests/end2end/features/notifications.feature10
-rw-r--r--tests/end2end/fixtures/notificationserver.py10
5 files changed, 24 insertions, 13 deletions
diff --git a/tests/end2end/data/javascript/img/big.png b/tests/end2end/data/javascript/img/big.png
new file mode 100644
index 000000000..37aa49ba3
--- /dev/null
+++ b/tests/end2end/data/javascript/img/big.png
Binary files differ
diff --git a/tests/end2end/data/javascript/img/padded.png b/tests/end2end/data/javascript/img/padded.png
new file mode 100644
index 000000000..9003df490
--- /dev/null
+++ b/tests/end2end/data/javascript/img/padded.png
Binary files differ
diff --git a/tests/end2end/data/javascript/notifications.html b/tests/end2end/data/javascript/notifications.html
index bfeadef8a..b93efdeaa 100644
--- a/tests/end2end/data/javascript/notifications.html
+++ b/tests/end2end/data/javascript/notifications.html
@@ -64,16 +64,9 @@
});
}
- function show_image_notification() {
+ function show_image_notification(title, filename) {
get_notification_permission(() => {
- let notification = new Notification("RGBA", { icon: 'img/rgba.png' });
- notification.onshow = function() { console.log("notification shown"); };
- });
- }
-
- function show_image_notification_noalpha() {
- get_notification_permission(() => {
- let notification = new Notification("RGB", { icon: 'img/rgb.png' });
+ let notification = new Notification(title, { icon: `img/${filename}` });
notification.onshow = function() { console.log("notification shown"); };
});
}
@@ -89,8 +82,10 @@
<input type="button" onclick="show_replacing_notifications()" value="Show replacing notifications" id="show-replacing-button">
</div>
<div>
- <input type="button" onclick="show_image_notification()" value="Show image notification" id="show-image-button">
- <input type="button" onclick="show_image_notification_noalpha()" value="Show image notification without alpha channel" id="show-image-button-noalpha">
+ <input type="button" onclick="show_image_notification('RGBA', 'rgba.png')" value="Show image notification" id="show-image-button">
+ <input type="button" onclick="show_image_notification('RGB', 'rgb.png')" value="Show image notification without alpha channel" id="show-image-button-noalpha">
+ <input type="button" onclick="show_image_notification('Big', 'big.png')" value="Show a big image notification" id="show-image-button-big">
+ <input type="button" onclick="show_image_notification('Padded', 'padded.png')" value="Show a padded image notification" id="show-image-button-padded">
</div>
</body>
</html>
diff --git a/tests/end2end/features/notifications.feature b/tests/end2end/features/notifications.feature
index 8367278f3..6cc94180f 100644
--- a/tests/end2end/features/notifications.feature
+++ b/tests/end2end/features/notifications.feature
@@ -37,6 +37,16 @@ Feature: Notifications
Then the javascript message "notification shown" should be logged
And notification 1 should have title "RGBA"
+ 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"
+
+ 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"
+
# 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/fixtures/notificationserver.py b/tests/end2end/fixtures/notificationserver.py
index 5c4fe6dd0..ecfac1842 100644
--- a/tests/end2end/fixtures/notificationserver.py
+++ b/tests/end2end/fixtures/notificationserver.py
@@ -124,10 +124,16 @@ class TestNotificationServer(QObject):
assert 0 < width <= 320
assert 0 < height <= 320
+ # Based on dunst:
+ # https://github.com/dunst-project/dunst/blob/v1.6.1/src/icon.c#L336-L348
+ # (A+7)/8 rounds up A to the next byte boundary
+ pixelstride = (channel_count * bits_per_color + 7) // 8
+ expected_len = (height - 1) * bytes_per_line + width * pixelstride
+ assert len(data) == expected_len
+
assert bits_per_color == 8
assert channel_count == (4 if has_alpha else 3)
- assert bytes_per_line == width * channel_count
- assert len(data) == height * bytes_per_line
+ assert bytes_per_line >= width * channel_count
qimage_format = QImage.Format_RGBA8888 if has_alpha else QImage.Format_RGB888
img = QImage(data, width, height, bytes_per_line, qimage_format)