Bug 1965258 - Clear active infobar when user closes the window the infobar is displayed in before interacting with it a=dmeehan DONTBUILD
Original Revision: https://phabricator.services.mozilla.com/D250465 Differential Revision: https://phabricator.services.mozilla.com/D252856
This commit is contained in:
committed by
dmeehan@mozilla.com
parent
b02be1715d
commit
39f4cca70c
@@ -280,6 +280,17 @@ export const InfoBar = {
|
||||
}
|
||||
if (!universalInNewWin) {
|
||||
this._activeInfobar = { message, dispatch };
|
||||
// If the window closes before the user interacts with the active infobar,
|
||||
// clear it
|
||||
win.addEventListener(
|
||||
"unload",
|
||||
() => {
|
||||
if (InfoBar._activeInfobar?.message === message) {
|
||||
InfoBar._activeInfobar = null;
|
||||
}
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
}
|
||||
|
||||
return notification;
|
||||
|
||||
@@ -526,3 +526,28 @@ add_task(async function test_dismissable_button_action() {
|
||||
|
||||
Assert.ok(!infobar.notification, "Infobar was dismissed after button click");
|
||||
});
|
||||
|
||||
add_task(async function clear_activeInfobar_on_window_close() {
|
||||
let message = (await CFRMessageProvider.getMessages()).find(
|
||||
m => m.id === "INFOBAR_ACTION_86"
|
||||
);
|
||||
Assert.ok(message.id, "Found the message");
|
||||
|
||||
let dispatchStub = sinon.stub();
|
||||
let testWin = await BrowserTestUtils.openNewBrowserWindow();
|
||||
let testBrowser = testWin.gBrowser.selectedBrowser;
|
||||
|
||||
await InfoBar.showInfoBarMessage(testBrowser, message, dispatchStub);
|
||||
Assert.ok(
|
||||
InfoBar._activeInfobar,
|
||||
"InfoBar._activeInfobar should be set after showing infobar"
|
||||
);
|
||||
|
||||
await BrowserTestUtils.closeWindow(testWin);
|
||||
await BrowserTestUtils.waitForCondition(
|
||||
() => !InfoBar._activeInfobar,
|
||||
"InfoBar._activeInfobar should be cleared when the window unloads"
|
||||
);
|
||||
testWin.close();
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user