Bug 1518663 - If policy extension download fails, try again. r=Felipe
☠☠ backed out by 56528eeda044 ☠ ☠
authorMichael Kaply <mozilla@kaply.com>
Tue, 02 Apr 2019 19:42:08 +0000
changeset 467681 29b08c635a7c7863ba4395ca9b7f74bdafc03aa2
parent 467680 fd9468269591a389893ae72182e9d998a2ef7854
child 467682 9ea2a2424ea54bc1d44e16382f330ae70919a01e
push id82122
push usermozilla@kaply.com
push dateWed, 03 Apr 2019 01:03:52 +0000
treeherderautoland@29b08c635a7c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe
bugs1518663
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1518663 - If policy extension download fails, try again. r=Felipe Differential Revision: https://phabricator.services.mozilla.com/D25830
browser/components/enterprisepolicies/Policies.jsm
browser/components/enterprisepolicies/tests/browser/browser_policy_extensions.js
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -547,16 +547,17 @@ var Policies = {
                     log.error(`Incompatible add-on - ${location}`);
                     install.removeListener(listener);
                     install.cancel();
                   }
                 },
                 onDownloadFailed: () => {
                   install.removeListener(listener);
                   log.error(`Download failed - ${location}`);
+                  clearRunOnceModification("extensionsInstall");
                 },
                 onInstallFailed: () => {
                   install.removeListener(listener);
                   log.error(`Installation failed - ${location}`);
                 },
                 onInstallEnded: () => {
                   install.removeListener(listener);
                   log.debug(`Installation succeeded - ${location}`);
@@ -1138,16 +1139,26 @@ async function runOncePerModification(ac
   if (policyValue === oldPolicyValue) {
     log.debug(`Not running action ${actionName} again because the policy's value is unchanged`);
     return Promise.resolve();
   }
   Services.prefs.setStringPref(prefName, policyValue);
   return callback();
 }
 
+/**
+ * clearRunOnceModification
+ *
+ * Helper function that clears a runOnce policy.
+*/
+function clearRunOnceModification(actionName) {
+  let prefName = `browser.policies.runOncePerModification.${actionName}`;
+  Services.prefs.clearUserPref(prefName);
+}
+
 let gChromeURLSBlocked = false;
 
 // If any about page is blocked, we block the loading of all
 // chrome:// URLs in the browser window.
 function blockAboutPage(manager, feature, neededOnContentProcess = false) {
   manager.disallowFeature(feature, neededOnContentProcess);
   if (!gChromeURLSBlocked) {
     blockAllChromeURLs();
--- a/browser/components/enterprisepolicies/tests/browser/browser_policy_extensions.js
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_extensions.js
@@ -87,16 +87,37 @@ add_task(async function test_addon_unins
       },
     },
   });
   await uninstallPromise;
   let addon = await AddonManager.getAddonByID(addonID);
   is(addon, null, "Addon should be uninstalled.");
 });
 
+add_task(async function test_addon_download_failure() {
+  // Test that if the download fails, the runOnce pref
+  // is cleared so that the dowbnload will happen again
+
+  let installPromise = wait_for_addon_install();
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "Extensions": {
+        "Install": [
+          `${BASE_URL}/policytest_invalid.xpi`,
+        ],
+      },
+    },
+  });
+
+  try {
+    await installPromise;
+  } catch (e) {}
+  is(Services.prefs.prefHasUserValue("browser.policies.runOncePerModification.extensionsInstall"), false, "runOnce pref should be unset");
+});
+
 function wait_for_addon_install() {
   return new Promise((resolve, reject) => {
       AddonManager.addInstallListener({
         onInstallEnded(install, addon) {
           if (addon.id == addonID) {
             resolve();
           }
         },