bug 1335697 Display permissions and post-install notifications from about:addons search r=mossop

MozReview-Commit-ID: IqBoudbO7Vd

--HG--
extra : rebase_source : d3fd4c63ac019c144dad1a1356ca63459684032e
This commit is contained in:
Andrew Swan 2017-02-07 20:22:26 -08:00
Родитель ad087668b7
Коммит 7d1313fec0
5 изменённых файлов: 142 добавлений и 3 удалений

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

@ -84,6 +84,7 @@ support-files =
browser_webext_update_perms1.xpi
browser_webext_update_perms2.xpi
browser_webext_update.json
browser_webext_search.xml
!/image/test/mochitest/blue.png
!/toolkit/content/tests/browser/common/mockTransfer.js
!/toolkit/modules/tests/browser/metadata_*.html

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

@ -8,8 +8,6 @@ const PERMS_XPI = "browser_webext_permissions.xpi";
const NO_PERMS_XPI = "browser_webext_nopermissions.xpi";
const ID = "permissions@test.mozilla.org";
const DEFAULT_EXTENSION_ICON = "chrome://browser/content/extension.svg";
Services.perms.add(makeURI("https://example.com/"), "install",
Services.perms.ALLOW_ACTION);
@ -21,6 +19,14 @@ registerCleanupFunction(async function() {
}
});
function isDefaultIcon(icon) {
// These are basically the same icon, but code within webextensions
// generates references to the former and generic add-ons manager code
// generates referces to the latter.
return (icon == "chrome://browser/content/extension.svg" ||
icon == "chrome://mozapps/skin/extensions/extensionGeneric.svg");
}
function promisePopupNotificationShown(name) {
return new Promise(resolve => {
function popupshown() {
@ -56,7 +62,7 @@ function checkNotification(panel, filename) {
// Real checking of the contents here is deferred until bug 1316996 lands
} else if (filename == NO_PERMS_XPI) {
// This extension has no icon, it should have the default
is(icon, DEFAULT_EXTENSION_ICON, "Icon is the default extension icon");
ok(isDefaultIcon(icon), "Icon is the default extension icon");
is(header.getAttribute("hidden"), "true", "Permission list header is hidden");
is(ul.childElementCount, 0, "Permissions list has 0 entries");
@ -106,6 +112,45 @@ const INSTALL_FUNCTIONS = [
contentWin.gViewController.doCommand("cmd_installFromFile");
MockFilePicker.cleanup();
},
async function installSearch(filename) {
await SpecialPowers.pushPrefEnv({set: [
["extensions.getAddons.maxResults", 10],
["extensions.getAddons.search.url", `${BASE}/browser_webext_search.xml`],
]});
let win = await BrowserOpenAddonsMgr("addons://list/extension");
let searchResultsPromise = new Promise(resolve => {
win.document.addEventListener("ViewChanged", resolve, {once: true});
});
let search = win.document.getElementById("header-search");
search.focus();
search.value = "search text";
EventUtils.synthesizeKey("VK_RETURN", {}, win);
await searchResultsPromise;
ok(win.gViewController.currentViewId.startsWith("addons://search"),
"about:addons is displaying search results");
let list = win.document.getElementById("search-list");
let item = null;
for (let child of list.childNodes) {
if (child.nodeName == "richlistitem" &&
child.mAddon.install.sourceURI.path.endsWith(filename)) {
item = child;
break;
}
}
ok(item, `Found ${filename} in search results`);
// abracadabara XBL
item.clientTop;
let install = win.document.getAnonymousElementByAttribute(item, "anonid", "install-status");
let button = win.document.getAnonymousElementByAttribute(install, "anonid", "install-remote-btn");
EventUtils.synthesizeMouseAtCenter(button, {}, win);
},
];
add_task(function* () {

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

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8" ?>
<searchresults total_results="2">
<addon>
<name>permissions test</name>
<type id='1'>Extension</type>
<guid>permissions@tests.mozilla.org</guid>
<version>1.1</version>
<authors>
<author>
<name>Test Creator</name>
<link>http://example.com/creator.html</link>
</author>
</authors>
<status id='4'>Public</status>
<compatible_applications>
<application>
<name>Firefox</name>
<appID>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</appID>
<min_version>0</min_version>
<max_version>*</max_version>
</application>
</compatible_applications>
<compatible_os>ALL</compatible_os>
<install size="1">https://example.com/browser/browser/base/content/test/general/browser_webext_permissions.xpi</install>
</addon>
<addon>
<name>no permissions</name>
<type id='1'>Extension</type>
<guid>nopermissions@tests.mozilla.org</guid>
<version>1.0</version>
<authors>
<author>
<name>Test Creator</name>
<link>http://example.com/creator.html</link>
</author>
</authors>
<status id='4'>Public</status>
<compatible_applications>
<application>
<name>Firefox</name>
<appID>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</appID>
<min_version>0</min_version>
<max_version>*</max_version>
</application>
</compatible_applications>
<compatible_os>ALL</compatible_os>
<install size="1">https://example.com/browser/browser/base/content/test/general/browser_webext_nopermissions.xpi</install>
</addon>
</searchresults>

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

@ -2715,6 +2715,27 @@ var gSearchView = {
this.removeInstall(aInstall);
},
onInstallEnded(aInstall) {
// If this is a webextension that was installed from this page,
// display the post-install notification.
if (!WEBEXT_PERMISSION_PROMPTS || !aInstall.addon.isWebExtension) {
return;
}
for (let item of this._listBox.childNodes) {
if (item.mInstall == aInstall) {
let subject = {
wrappedJSObject: {
target: getBrowserElement(),
addon: aInstall.addon,
},
};
Services.obs.notifyObservers(subject, "webextension-install-notify", null);
return;
}
}
},
removeInstall(aInstall) {
for (let item of this._listBox.childNodes) {
if (item.mInstall == aInstall) {

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

@ -653,6 +653,27 @@
delete this.mControl.mAddon;
this.mControl.mInstall = this.mInstall;
this.mControl.setAttribute("status", "installing");
let prompt = false;
try {
prompt = Services.prefs.getBoolPref("extensions.webextPermissionPrompts");
} catch (err) {}
if (prompt) {
this.mInstall.promptHandler = info => new Promise((resolve, reject) => {
let subject = {
wrappedJSObject: {
target: window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDocShell).chromeEventHandler,
info: {
addon: info.addon,
icon: info.addon.iconURL,
resolve,
reject,
},
},
};
Services.obs.notifyObservers(subject, "webextension-permission-prompt", null);
});
}
this.mInstall.install();
]]></body>
</method>