From 5808ddd4ec487bbc1c8cbc90bca7a43257856e58 Mon Sep 17 00:00:00 2001 From: bsilverberg Date: Wed, 6 Apr 2016 13:24:12 -0400 Subject: [PATCH] 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 --- .../test/browser/browser_ext_getViews.js | 49 ++++++++++++------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/browser/components/extensions/test/browser/browser_ext_getViews.js b/browser/components/extensions/test/browser/browser_ext_getViews.js index f071a4558ebc..24bd6c71ad0e 100644 --- a/browser/components/extensions/test/browser/browser_ext_getViews.js +++ b/browser/components/extensions/test/browser/browser_ext_getViews.js @@ -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();