Bug 1451748: Always remove unloaded views from views list. r=mixedpuppy

Contexts for active extension views are kept in a Set on the owning extension.
That list is meant to be kept current, with views added and removed as they're
created and unloaded. A refactoring at some point in the past, though, changed
that so that we only cleaned up parent views at extension shutdown, not at
view shutdown.

MozReview-Commit-ID: FW8KHPOD9qc

--HG--
extra : rebase_source : fab255ba2fb5ee55be41c252c89930d38f6edbe8
extra : amend_source : 54863d79a1d571a7354aa15f74e2fc4448297777
This commit is contained in:
Kris Maglione 2018-04-05 19:42:20 -07:00
Родитель 4240ca317d
Коммит 27b1c032a5
3 изменённых файлов: 27 добавлений и 2 удалений

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

@ -2,13 +2,20 @@
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
const {GlobalManager} = ChromeUtils.import("resource://gre/modules/Extension.jsm", null);
function getBrowserAction(extension) {
const {GlobalManager, Management: {global: {browserActionFor}}} = ChromeUtils.import("resource://gre/modules/Extension.jsm", {});
const {global: {browserActionFor}} = Management;
let ext = GlobalManager.extensionMap.get(extension.id);
return browserActionFor(ext);
}
function assertViewCount(extension, count) {
let ext = GlobalManager.extensionMap.get(extension.id);
is(ext.views.size, count, "Should have the expected number of extension views");
}
let scriptPage = url => `<html><head><meta charset="utf-8"><script src="${url}"></script></head><body>${url}</body></html>`;
async function testInArea(area) {
@ -204,6 +211,8 @@ async function testInArea(area) {
info("Popup is open. Waiting for close");
await promisePopupHidden(panel);
}
assertViewCount(extension, 1);
} else if (expecting.closePopupUsingWindow) {
let panel = getBrowserActionPopup(extension);
ok(panel, "Expect panel to exist");
@ -213,6 +222,8 @@ async function testInArea(area) {
await promisePopupHidden(panel);
ok(true, "Panel is closed");
assertViewCount(extension, 1);
} else if (expecting.closePopup) {
if (!getBrowserActionPopup(extension)) {
info("Waiting for panel");
@ -221,6 +232,7 @@ async function testInArea(area) {
info("Closing for panel");
await closeBrowserAction(extension);
assertViewCount(extension, 1);
}
if (area == getCustomizableUIPanelID() && expecting.containingPopupShouldClose) {

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

@ -2,6 +2,13 @@
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
const {GlobalManager} = ChromeUtils.import("resource://gre/modules/Extension.jsm", null);
function assertViewCount(extension, count) {
let ext = GlobalManager.extensionMap.get(extension.id);
is(ext.views.size, count, "Should have the expected number of extension views");
}
add_task(async function testPageActionPopup() {
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com/");
@ -178,6 +185,8 @@ add_task(async function testPageActionPopup() {
panel.hidePopup();
}
assertViewCount(extension, 1);
if (panel) {
panel = document.getElementById(panelId);
is(panel, null, "panel successfully removed from document after hiding");

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

@ -587,9 +587,13 @@ class ExtensionPageContextParent extends ProxyContextParent {
this.xulBrowser = browser;
}
unload() {
super.unload();
this.extension.views.delete(this);
}
shutdown() {
apiManager.emit("page-shutdown", this);
this.extension.views.delete(this);
super.shutdown();
}
}