From d1a8772ac82d84ab76c274ca99cb16b0b70c909b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 28 Jul 2024 17:27:09 +0530 Subject: [PATCH] Add tests for alive queries --- kitty/cocoa_window.m | 10 ++++++---- kitty_tests/notifications.py | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index c388ed2be..f3366b178 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -489,10 +489,12 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center UNUserNotificationCenter *center = get_notification_center_safely(); if (!center) return false; [center getDeliveredNotificationsWithCompletionHandler:^(NSArray * notifications) { - NSMutableString *buffer = [[NSMutableString stringWithCapacity:1024] autorelease]; - for (UNNotification *n in notifications) [buffer appendFormat:@"%@,", [[n request] identifier]]; - const char *val = [buffer UTF8String]; - set_cocoa_pending_action(COCOA_NOTIFICATION_UNTRACKED, val ? val : ""); + @autoreleasepool { + NSMutableString *buffer = [NSMutableString stringWithCapacity:1024]; // autoreleased + for (UNNotification *n in notifications) [buffer appendFormat:@"%@,", [[n request] identifier]]; + const char *val = [buffer UTF8String]; + set_cocoa_pending_action(COCOA_NOTIFICATION_UNTRACKED, val ? val : ""); + } }]; return true; } diff --git a/kitty_tests/notifications.py b/kitty_tests/notifications.py index d3f2cf24a..c0de39d3c 100644 --- a/kitty_tests/notifications.py +++ b/kitty_tests/notifications.py @@ -30,6 +30,10 @@ def reset(self): self.close_succeeds = True self.counter = 0 + def query_live_notifications(self, channel_id, client_id): + ids = [n['id'] for n in self.notifications] + self.notification_manager.send_live_response(channel_id, client_id, tuple(ids)) + def on_new_version_notification_activation(self, cmd) -> None: self.new_version_activated = True @@ -102,7 +106,7 @@ def close(which=0): n = di.notifications[which] di.close_notification(n['id']) - def assert_events(focus=True, close=0, report='', close_response=''): + def assert_events(focus=True, close=0, report='', close_response='', live=''): self.ae(ch.focus_events, [''] if focus else []) if report: self.assertIn(f'99;i={report};', ch.responses) @@ -116,6 +120,12 @@ def assert_events(focus=True, close=0, report='', close_response=''): for r in ch.responses: m = re.match(r'99;i=[a-z0-9]+:p=close;', r) self.assertIsNone(m, f'Unexpectedly found close response: {r}') + if live: + self.assertIn(f'99;i=live:p=alive;{live}', ch.responses) + else: + for r in ch.responses: + m = re.match(r'99;i=[a-z0-9]+:p=alive;', r) + self.assertIsNone(m, f'Unexpectedly found alive response: {r}') self.ae(di.close_events, [close] if close else []) h('test it', osc_code=9) @@ -210,6 +220,12 @@ def assert_events(focus=True, close=0, report='', close_response=''): assert_events(focus=True, report='c', close=True, close_response='c') reset() + h('i=a;title') + h('i=b;title') + h('i=live:p=alive;') + assert_events(focus=False, live='a,b') + reset() + h(';title') self.ae(di.notifications, [n()]) activate()