--- a/browser/components/extensions/test/browser/browser_ext_getViews.js
+++ b/browser/components/extensions/test/browser/browser_ext_getViews.js
@@ -9,22 +9,31 @@ function genericChecker() {
kind = "popup";
} else if (path.indexOf("tab") != -1) {
kind = "tab";
}
window.kind = kind;
browser.test.onMessage.addListener((msg, ...args) => {
if (msg == kind + "-check-views") {
- let views = browser.extension.getViews();
+ let windowId = args[0];
let counts = {
"background": 0,
"tab": 0,
"popup": 0,
+ "kind": 0,
+ "window": 0,
};
+ if (Number.isInteger(windowId)) {
+ counts.window = browser.extension.getViews({windowId: windowId}).length;
+ }
+ if (kind !== "background") {
+ counts.kind = browser.extension.getViews({type: kind}).length;
+ }
+ let views = browser.extension.getViews();
let background;
for (let i = 0; i < views.length; i++) {
let view = views[i];
browser.test.assertTrue(view.kind in counts, "view type is valid");
counts[view.kind]++;
if (view.kind == "background") {
browser.test.assertTrue(view === browser.extension.getBackgroundPage(),
"background page is correct");
@@ -100,34 +109,36 @@ add_task(function* () {
let winId1 = WindowManager.getId(win1);
let winId2 = WindowManager.getId(win2);
function* openTab(winId) {
extension.sendMessage("background-open-tab", winId);
yield extension.awaitMessage("tab-ready");
}
- function* checkViews(kind, tabCount, popupCount) {
- extension.sendMessage(kind + "-check-views");
+ function* checkViews(kind, tabCount, popupCount, kindCount, windowId = undefined, windowCount = 0) {
+ extension.sendMessage(kind + "-check-views", windowId);
let counts = yield extension.awaitMessage("counts");
is(counts.background, 1, "background count correct");
is(counts.tab, tabCount, "tab count correct");
is(counts.popup, popupCount, "popup count correct");
+ is(counts.kind, kindCount, "count for type correct");
+ is(counts.window, windowCount, "count for window correct");
}
- yield checkViews("background", 0, 0);
+ yield checkViews("background", 0, 0, 0);
yield openTab(winId1);
- yield checkViews("background", 1, 0);
- yield checkViews("tab", 1, 0);
+ yield checkViews("background", 1, 0, 0, winId1, 1);
+ yield checkViews("tab", 1, 0, 1);
yield openTab(winId2);
- yield checkViews("background", 2, 0);
+ yield checkViews("background", 2, 0, 0, winId2, 1);
function* triggerPopup(win, callback) {
yield clickBrowserAction(extension, win);
yield extension.awaitMessage("popup-ready");
yield callback();
@@ -136,51 +147,51 @@ add_task(function* () {
// The popup occasionally closes prematurely if we open it immediately here.
// I'm not sure what causes it to close (it's something internal, and seems to
// be focus-related, but it's not caused by JS calling hidePopup), but even a
// short timeout seems to consistently fix it.
yield new Promise(resolve => win1.setTimeout(resolve, 10));
yield triggerPopup(win1, function* () {
- yield checkViews("background", 2, 1);
- yield checkViews("popup", 2, 1);
+ yield checkViews("background", 2, 1, 0, winId1, 2);
+ yield checkViews("popup", 2, 1, 1);
});
yield triggerPopup(win2, function* () {
- yield checkViews("background", 2, 1);
- yield checkViews("popup", 2, 1);
+ yield checkViews("background", 2, 1, 0, winId2, 2);
+ yield checkViews("popup", 2, 1, 1);
});
info("checking counts after popups");
- yield checkViews("background", 2, 0);
+ yield checkViews("background", 2, 0, 0, winId1, 1);
info("closing one tab");
extension.sendMessage("background-close-tab", winId1);
yield extension.awaitMessage("closed");
info("one tab closed, one remains");
- yield checkViews("background", 1, 0);
+ yield checkViews("background", 1, 0, 0);
info("opening win1 popup");
yield triggerPopup(win1, function* () {
- yield checkViews("background", 1, 1);
- yield checkViews("tab", 1, 1);
- yield checkViews("popup", 1, 1);
+ yield checkViews("background", 1, 1, 0);
+ yield checkViews("tab", 1, 1, 1);
+ yield checkViews("popup", 1, 1, 1);
});
info("opening win2 popup");
yield triggerPopup(win2, function* () {
- yield checkViews("background", 1, 1);
- yield checkViews("tab", 1, 1);
- yield checkViews("popup", 1, 1);
+ yield checkViews("background", 1, 1, 0);
+ yield checkViews("tab", 1, 1, 1);
+ yield checkViews("popup", 1, 1, 1);
});
yield extension.unload();
yield BrowserTestUtils.closeWindow(win1);
yield BrowserTestUtils.closeWindow(win2);
});