Retire extension notification records on native activation (#35139)

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-10-28 11:29:23 -07:00
committed by GitHub
co-authored by OrcaWin
parent 80bbbaff7f
commit 02b6bde705
2 changed files with 35 additions and 0 deletions
@@ -37,6 +37,7 @@ const { registerNotificationsNamespace, resolveNotificationIconPath } =
await import('./notifications')
const { getBrowserExtensionNamespace } = await import('../browser-extension-namespace-registry')
const { emitBrowserExtensionEvent } = await import('../browser-extension-api-host')
const { noteBrowserExtensionUserGesture } = await import('./permissions')
registerNotificationsNamespace()
const extension = { id: 'a'.repeat(32), path: join('/ext', 'root') }
@@ -82,6 +83,38 @@ function invoke(caller: BrowserExtensionCaller, method: string, args: unknown[]
const options = { type: 'basic', title: 'Notification', message: 'Retire with its extension' }
describe('notification extension ownership', () => {
it('retires an activated notification while preserving click delivery and its successor', () => {
const { caller } = notificationCaller('clicked')
const sibling = { ...caller, extension: { ...caller.extension, id: 'b'.repeat(32) } }
invoke(caller, 'create', ['clicked', options])
invoke(sibling, 'create', ['sibling', options])
const clicked = mocks.notifications[0]
clicked.emit('click')
expect(emitBrowserExtensionEvent).toHaveBeenCalledExactlyOnceWith(
{ session: caller.session, extensionId: caller.extension.id },
'notifications',
'onClicked',
['clicked']
)
expect(noteBrowserExtensionUserGesture).toHaveBeenCalledExactlyOnceWith(
caller.session,
caller.extension.id
)
expect(invoke(caller, 'getAll')).toEqual({})
expect(invoke(caller, 'clear', ['clicked'])).toBe(false)
expect(invoke(sibling, 'getAll')).toEqual({ sibling: true })
expect(clicked.close).not.toHaveBeenCalled()
expect(clicked.eventNames()).toEqual([])
invoke(caller, 'create', ['clicked', options])
clicked.emit('click')
clicked.emit('close', {})
expect(invoke(caller, 'getAll')).toEqual({ clicked: true })
expect(emitBrowserExtensionEvent).toHaveBeenCalledTimes(1)
})
it.each(['create', 'update'])(
'forgets a failed native %s without reporting a dismissal',
(method) => {
@@ -129,6 +129,8 @@ function show(caller: BrowserExtensionCaller, id: string, entry: Shown): void {
: {})
})
notification.on('click', () => {
shownFor(caller).delete(id)
detach(entry, false)
noteBrowserExtensionUserGesture(caller.session, caller.extension.id)
emit(caller, 'onClicked', [id])
})