Bug 1339552 Don't show permissions for updates from legacy extension to webextension r=mossop

MozReview-Commit-ID: 9Ouep0mPIjJ

--HG--
extra : rebase_source : e9f5f155b0c1050d9b20025ea6edb20f52f8fb68
This commit is contained in:
Andrew Swan 2017-02-16 09:17:52 -08:00
Родитель f7884afffa
Коммит e37c8152ee
8 изменённых файлов: 99 добавлений и 18 удалений

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

@ -75,6 +75,8 @@ support-files =
web_video1.ogv^headers^
zoom_test.html
file_install_extensions.html
browser_legacy.xpi
browser_legacy_webext.xpi
browser_webext_permissions.xpi
browser_webext_nopermissions.xpi
browser_webext_update1.xpi

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

@ -3,9 +3,11 @@ const {AddonManagerPrivate} = Cu.import("resource://gre/modules/AddonManager.jsm
const URL_BASE = "https://example.com/browser/browser/base/content/test/general";
const ID = "update@tests.mozilla.org";
const ID_ICON = "update_icon@tests.mozilla.org";
const ID_PERMS = "update_perms@tests.mozilla.org";
const ID_LEGACY = "legacy_update@tests.mozilla.org";
registerCleanupFunction(async function() {
for (let id of [ID, ID_ICON]) {
for (let id of [ID, ID_ICON, ID_PERMS, ID_LEGACY]) {
let addon = await AddonManager.getAddonByID(id);
if (addon) {
ok(false, `Addon ${id} was still installed at the end of the test`);
@ -232,10 +234,9 @@ function checkNonDefaultIcon(icon) {
add_task(() => backgroundUpdateTest(`${URL_BASE}/browser_webext_update_icon1.xpi`,
ID_ICON, checkNonDefaultIcon));
// Test that an update that adds new non-promptable permissions is just
// applied without showing a notification dialog.
add_task(function*() {
yield SpecialPowers.pushPrefEnv({set: [
// Helper function to test an upgrade that should not show a prompt
async function testNoPrompt(origUrl, id) {
await SpecialPowers.pushPrefEnv({set: [
// Turn on background updates
["extensions.update.enabled", true],
@ -244,7 +245,7 @@ add_task(function*() {
]});
// Install version 1.0 of the test extension
let addon = yield promiseInstallAddon(`${URL_BASE}/browser_webext_update_perms1.xpi`);
let addon = await promiseInstallAddon(origUrl);
ok(addon, "Addon was installed");
@ -256,21 +257,32 @@ add_task(function*() {
// Trigger an update check and wait for the update to be applied.
let updatePromise = promiseInstallEvent(addon, "onInstallEnded");
AddonManagerPrivate.backgroundUpdateCheck();
yield updatePromise;
await updatePromise;
// There should be no notifications about the update
is(getBadgeStatus(), "", "Should not have addon alert badge");
yield PanelUI.show();
await PanelUI.show();
let addons = document.getElementById("PanelUI-footer-addons");
is(addons.children.length, 0, "Have 0 updates in the PanelUI menu");
yield PanelUI.hide();
await PanelUI.hide();
ok(!sawPopup, "Should not have seen permissions notification");
addon = yield AddonManager.getAddonByID("update_perms@tests.mozilla.org");
addon = await AddonManager.getAddonByID(id);
is(addon.version, "2.0", "Update should have applied");
addon.uninstall();
yield SpecialPowers.popPrefEnv();
});
await SpecialPowers.popPrefEnv();
}
// Test that an update that adds new non-promptable permissions is just
// applied without showing a notification dialog.
add_task(() => testNoPrompt(`${URL_BASE}/browser_webext_update_perms1.xpi`,
ID_PERMS));
// Test that an update from a legacy extension to a webextension
// doesn't show a prompt even when the webextension uses
// promptable required permissions.
add_task(() => testNoPrompt(`${URL_BASE}/browser_legacy.xpi`, ID_LEGACY));

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

@ -2,12 +2,15 @@ const {AddonManagerPrivate} = Cu.import("resource://gre/modules/AddonManager.jsm
const URL_BASE = "https://example.com/browser/browser/base/content/test/general";
const ID = "update@tests.mozilla.org";
const ID_LEGACY = "legacy_update@tests.mozilla.org";
registerCleanupFunction(async function() {
let addon = await AddonManager.getAddonByID(ID);
if (addon) {
ok(false, `Addon ${ID} was still installed at the end of the test`);
addon.uninstall();
for (let id of [ID, ID_LEGACY]) {
let addon = await AddonManager.getAddonByID(id);
if (addon) {
ok(false, `Addon ${id} was still installed at the end of the test`);
addon.uninstall();
}
}
});
@ -202,3 +205,43 @@ function checkOne(win, addon) {
// Test "Find Updates" with both auto-update settings
add_task(() => interactiveUpdateTest(true, checkOne));
add_task(() => interactiveUpdateTest(false, checkOne));
// Check that an update from a legacy extension to a webextensino
// does not display a prompt
add_task(async function() {
await SpecialPowers.pushPrefEnv({set: [
// Point updates to the local mochitest server
["extensions.update.url", `${URL_BASE}/browser_webext_update.json`],
]});
// Navigate away to ensure that BrowserOpenAddonMgr() opens a new tab
gBrowser.selectedBrowser.loadURI("about:robots");
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
// Install initial version of the test extension
let addon = await promiseInstallAddon(`${URL_BASE}/browser_legacy.xpi`);
ok(addon, "Addon was installed");
is(addon.version, "1.1", "Version 1 of the addon is installed");
// Go to Extensions in about:addons
let win = await BrowserOpenAddonsMgr("addons://list/extension");
let sawPopup = false;
PopupNotifications.panel.addEventListener("popupshown",
() => sawPopup = true,
{once: true});
// Trigger an update check, we should see the update get applied
let updatePromise = promiseInstallEvent(addon, "onInstallEnded");
win.gViewController.doCommand("cmd_findAllUpdates");
await updatePromise;
addon = await AddonManager.getAddonByID(ID_LEGACY);
is(addon.version, "2.0", "Should have upgraded");
ok(!sawPopup, "Should not have seen a permission notification");
await BrowserTestUtils.removeTab(gBrowser.selectedTab);
addon.uninstall();
await SpecialPowers.popPrefEnv();
});

Двоичные данные
browser/base/content/test/general/browser_legacy.xpi Normal file

Двоичный файл не отображается.

Двоичные данные
browser/base/content/test/general/browser_legacy_webext.xpi Normal file

Двоичный файл не отображается.

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

@ -41,6 +41,20 @@
}
}
]
},
"legacy_update@tests.mozilla.org": {
"updates": [
{
"version": "2.0",
"update_link": "https://example.com/browser/browser/base/content/test/general/browser_legacy_webext.xpi",
"applications": {
"gecko": {
"strict_min_version": "1",
"advisory_max_version": "*"
}
}
}
]
}
}
}

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

@ -1377,7 +1377,12 @@ var AddonManagerInternal = {
},
_updatePromptHandler(info) {
let oldPerms = info.existingAddon.userPermissions || {hosts: [], permissions: []};
let oldPerms = info.existingAddon.userPermissions;
if (!oldPerms) {
// Updating from a legacy add-on, just let it proceed
return Promise.resolve();
}
let newPerms = info.addon.userPermissions;
let difference = Extension.comparePermissions(oldPerms, newPerms);

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

@ -705,7 +705,12 @@ function attachUpdateHandler(install) {
}
install.promptHandler = (info) => {
let oldPerms = info.existingAddon.userPermissions || {hosts: [], permissions: []};
let oldPerms = info.existingAddon.userPermissions;
if (!oldPerms) {
// Updating from a legacy add-on, let it proceed
return Promise.resolve();
}
let newPerms = info.addon.userPermissions;
let difference = Extension.comparePermissions(oldPerms, newPerms);