From 1d3b1284c46b8a9db3a16da090675a7882c86e4f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 25 Sep 2024 06:20:36 -0500 Subject: [PATCH] test: ensure `sender-pid` hint is set in Linux notifications (#43928) test: expect a `sender-pid` hint in Linux notifications. This PR ensures that the `sender-pid` hint is set for new notifications. It also updates the spec to confirm that DBus receives the hint and that it has the correct value. This fixes a spec failure when running libnotify >= 0.7.12 (2022-05-05). Starting with that version, libnotify started injecting `sender-pid` if not provided by the client. So our tests received a slightly different DBus payload depending on what version of libnotify was installed, causing our deep-equals tests to fail. By always providing and testing the `sender-pid` hint, our behavior and tests should be consistent across distros. --- BUILD.gn | 1 + shell/browser/notifications/linux/libnotify_notification.cc | 5 +++++ spec/api-notification-dbus-spec.ts | 1 + 3 files changed, 7 insertions(+) diff --git a/BUILD.gn b/BUILD.gn index 83d1cee62f..722f813b4f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -75,6 +75,7 @@ if (is_linux) { "notify_notification_set_timeout", "notify_notification_set_urgency", "notify_notification_set_hint_string", + "notify_notification_set_hint", "notify_notification_show", "notify_notification_close", ] diff --git a/shell/browser/notifications/linux/libnotify_notification.cc b/shell/browser/notifications/linux/libnotify_notification.cc index 4c8452fad1..4b6c6cf897 100644 --- a/shell/browser/notifications/linux/libnotify_notification.cc +++ b/shell/browser/notifications/linux/libnotify_notification.cc @@ -10,6 +10,7 @@ #include "base/files/file_enumerator.h" #include "base/functional/bind.h" #include "base/logging.h" +#include "base/process/process_handle.h" #include "base/strings/utf_string_conversions.h" #include "shell/browser/notifications/notification_delegate.h" #include "shell/browser/ui/gtk_util.h" @@ -145,6 +146,10 @@ void LibnotifyNotification::Show(const NotificationOptions& options) { notification_, "desktop-entry", desktop_id.c_str()); } + libnotify_loader_.notify_notification_set_hint( + notification_, "sender-pid", + g_variant_new_int64(base::GetCurrentProcId())); + GError* error = nullptr; libnotify_loader_.notify_notification_show(notification_, &error); if (error) { diff --git a/spec/api-notification-dbus-spec.ts b/spec/api-notification-dbus-spec.ts index 3d359a307b..d470bbd20c 100644 --- a/spec/api-notification-dbus-spec.ts +++ b/spec/api-notification-dbus-spec.ts @@ -124,6 +124,7 @@ ifdescribe(!skip)('Notification module (dbus)', () => { append: 'true', image_data: [3, 3, 12, true, 8, 4, Buffer.from([255, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 76, 255, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 38, 255, 255, 0, 0, 0, 255, 0, 0, 0, 0])], 'desktop-entry': appName, + 'sender-pid': process.pid, urgency: 1 } });