mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 07:15:46 +00:00
Bug 1190322 - Test coverage for |extension| extension API, r=kmag
Add coverage for: * The |getViews| API method with a |type| property. * The |getViews| API method with a |windowId| property. MozReview-Commit-ID: Evoi8au0wzW --HG-- extra : transplant_source : %A9%2AX%D8f8%D6%5CQ%AD%CB%83%A5%B2f%FA%98%B4%EA%C0
This commit is contained in:
parent
e7e4a7abbf
commit
5808ddd4ec
@ -14,12 +14,21 @@ function genericChecker() {
|
||||
|
||||
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];
|
||||
@ -105,24 +114,26 @@ add_task(function* () {
|
||||
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);
|
||||
@ -141,18 +152,18 @@ add_task(function* () {
|
||||
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");
|
||||
|
||||
@ -161,22 +172,22 @@ add_task(function* () {
|
||||
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user