Bug 1660201 - Don't try to access node on domwindowclosed in ToolbarPanelHub.jsm r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D87758
This commit is contained in:
Andrei Oprea 2020-08-21 12:16:35 +00:00
Родитель 0cd6331277
Коммит 0d84d6441b
2 изменённых файлов: 20 добавлений и 3 удалений

Просмотреть файл

@ -463,8 +463,11 @@ class _ToolbarPanelHub {
);
}
_hideAppmenuButton(win) {
this._hideElement(win.browser.ownerDocument, APPMENU_BUTTON_ID);
_hideAppmenuButton(win, windowClosed) {
// No need to do something if the window is going away
if (!windowClosed) {
this._hideElement(win.browser.ownerDocument, APPMENU_BUTTON_ID);
}
}
_showToolbarButton(win) {
@ -484,7 +487,10 @@ class _ToolbarPanelHub {
}
_hideElement(document, id) {
document.getElementById(id).setAttribute("hidden", true);
const el = PanelMultiView.getViewNode(document, id);
if (el) {
el.setAttribute("hidden", true);
}
}
_sendTelemetry(ping) {

Просмотреть файл

@ -295,6 +295,17 @@ describe("ToolbarPanelHub", () => {
instance._hideAppmenuButton(fakeWindow);
assert.calledWith(fakeElementById.setAttribute, "hidden", true);
});
it("should not do anything if the window is closed", () => {
instance._hideAppmenuButton(fakeWindow, true);
assert.notCalled(PanelMultiView.getViewNode);
});
it("should not throw if the element does not exist", () => {
let fn = instance._hideAppmenuButton.bind(null, {
browser: { ownerDocument: {} },
});
getViewNodeStub.returns(undefined);
assert.doesNotThrow(fn);
});
it("should unhide toolbar button on _showToolbarButton()", async () => {
await instance._showToolbarButton(fakeWindow);