Bug 1299053 - support tabId in browser.extension.getViews r=aswan

MozReview-Commit-ID: Ep6pdUdbhmc

--HG--
extra : rebase_source : 9554e9e529c496ddc91db73aa5416bc967cd548b
This commit is contained in:
Rob Wu 2017-04-23 13:01:34 +02:00
Родитель be45f9a848
Коммит ebbe4943f0
4 изменённых файлов: 27 добавлений и 4 удалений

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

@ -48,7 +48,8 @@ function genericChecker() {
let count = browser.extension.getViews(filter).length;
browser.test.sendMessage("getViews-count", count);
} else if (msg == kind + "-open-tab") {
browser.tabs.create({windowId: args[0], url: browser.runtime.getURL("tab.html")});
browser.tabs.create({windowId: args[0], url: browser.runtime.getURL("tab.html")})
.then((tab) => browser.test.sendMessage("opened-tab", tab.id));
} else if (msg == kind + "-close-tab") {
browser.tabs.query({
windowId: args[0],
@ -111,6 +112,7 @@ add_task(async function() {
async function openTab(winId) {
extension.sendMessage("background-open-tab", winId);
await extension.awaitMessage("tab-ready");
return extension.awaitMessage("opened-tab");
}
async function checkViews(kind, tabCount, popupCount, kindCount) {
@ -129,17 +131,20 @@ add_task(async function() {
}
await checkViews("background", 0, 0, 0);
await checkViewsWithFilter({tabId: -1}, 1);
await openTab(winId1);
let tabId1 = await openTab(winId1);
await checkViews("background", 1, 0, 0);
await checkViews("tab", 1, 0, 1);
await checkViewsWithFilter({windowId: winId1}, 1);
await checkViewsWithFilter({tabId: tabId1}, 1);
await openTab(winId2);
let tabId2 = await openTab(winId2);
await checkViews("background", 2, 0, 0);
await checkViewsWithFilter({windowId: winId2}, 1);
await checkViewsWithFilter({tabId: tabId2}, 1);
async function triggerPopup(win, callback) {
await clickBrowserAction(extension, win);
@ -162,18 +167,21 @@ add_task(async function() {
await checkViews("background", 2, 1, 0);
await checkViews("popup", 2, 1, 1);
await checkViewsWithFilter({windowId: winId1}, 2);
await checkViewsWithFilter({type: "popup", tabId: -1}, 1);
});
await triggerPopup(win2, async function() {
await checkViews("background", 2, 1, 0);
await checkViews("popup", 2, 1, 1);
await checkViewsWithFilter({windowId: winId2}, 2);
await checkViewsWithFilter({type: "popup", tabId: -1}, 1);
});
info("checking counts after popups");
await checkViews("background", 2, 0, 0);
await checkViewsWithFilter({windowId: winId1}, 1);
await checkViewsWithFilter({tabId: -1}, 1);
info("closing one tab");

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

@ -116,7 +116,8 @@ class ExtensionBaseContextChild extends BaseContext {
if (viewType == "tab") {
sender.frameId = WebNavigationFrames.getFrameId(contentWindow);
sender.tabId = tabId;
this.tabId = tabId;
Object.defineProperty(this, "tabId",
{value: tabId, enumerable: true, configurable: true});
}
if (uri) {
sender.url = uri.spec;
@ -154,6 +155,11 @@ class ExtensionBaseContextChild extends BaseContext {
}
}
get tabId() {
// Will be overwritten in the constructor if necessary.
return -1;
}
// Called when the extension shuts down.
shutdown() {
this.unload();

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

@ -39,6 +39,10 @@ this.extension = class extends ExtensionAPI {
if (fetchProperties.windowId !== null && view.windowId != fetchProperties.windowId) {
continue;
}
if (fetchProperties.tabId !== null && view.tabId != fetchProperties.tabId) {
continue;
}
}
result.push(view.contentWindow);

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

@ -72,6 +72,11 @@
"type": "integer",
"optional": true,
"description": "The window to restrict the search to. If omitted, returns all views."
},
"tabId": {
"type": "integer",
"optional":true,
"description": "Find a view according to a tab id. If this field is omitted, returns all views."
}
}
}