Commit 0ff5df9d authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃
Browse files

Bug 1923264 - Discard unsupported updates in selectUpdate. r=bytesized,nalexander

UpdateService.#selectUpdate currently chooses always the most recent
update even when unsupported and an older but supported one is
available.
This commit makes #selectUpdate discard the unsupported update if a
supported alternative is found.

Differential Revision: https://phabricator.services.mozilla.com/D224905
parent 1e28f3fc
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -3657,18 +3657,20 @@ export class UpdateService {

      switch (update.type) {
        case "major":
          if (!majorUpdate) {
          if (!majorUpdate || majorUpdate.unsupported) {
            majorUpdate = update;
          } else if (
            !update.unsupported &&
            vc.compare(majorUpdate.appVersion, update.appVersion) <= 0
          ) {
            majorUpdate = update;
          }
          break;
        case "minor":
          if (!minorUpdate) {
          if (!minorUpdate || minorUpdate.unsupported) {
            minorUpdate = update;
          } else if (
            !update.unsupported &&
            vc.compare(minorUpdate.appVersion, update.appVersion) <= 0
          ) {
            minorUpdate = update;
+3 −0
Original line number Diff line number Diff line
@@ -141,6 +141,7 @@ function getRemoteUpdateString(aUpdateProps, aPatches) {
    name: "App Update Test",
    promptWaitTime: null,
    type: "major",
    unsupported: false,
  };

  for (let name in aUpdateProps) {
@@ -346,6 +347,7 @@ function getUpdateString(aUpdateProps) {
      aUpdateProps.disableBackgroundUpdates +
      '" '
    : "";
  let unsupported = aUpdateProps.unsupported ? 'unsupported="true" ' : "";
  let custom1 = aUpdateProps.custom1 ? aUpdateProps.custom1 + " " : "";
  let custom2 = aUpdateProps.custom2 ? aUpdateProps.custom2 + " " : "";
  let buildID = 'buildID="' + aUpdateProps.buildID + '"';
@@ -360,6 +362,7 @@ function getUpdateString(aUpdateProps) {
    promptWaitTime +
    disableBITS +
    disableBackgroundUpdates +
    unsupported +
    custom1 +
    custom2 +
    buildID
+50 −0
Original line number Diff line number Diff line
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

/**
 * This tests that an older update is chosen over a more recent but unsupported
 * update.
 */

async function run_test() {
  setupTestCommon();
  start_httpserver();
  setUpdateURL(gURLData + gHTTPHandlerPath);
  setUpdateChannel("test_channel");

  let patchProps = {
    type: "complete",
    url: "http://complete/",
    size: "9856459",
  };
  let patches = getRemotePatchString(patchProps);
  patchProps = { type: "partial", url: "http://partial/", size: "1316138" };
  patches += getRemotePatchString(patchProps);

  let oldAppVersion = "900000.0";
  let newAppVersion = "999999.0";
  let update1 = getRemoteUpdateString(
    { appVersion: newAppVersion, unsupported: true },
    patches
  );
  let update2 = getRemoteUpdateString({ appVersion: oldAppVersion }, patches);
  gResponseBody = getRemoteUpdatesXMLString(update1 + update2);

  let checkResult = await waitForUpdateCheck(true, { updateCount: 2 });
  let bestUpdate = await gAUS.selectUpdate(checkResult.updates);
  bestUpdate.QueryInterface(Ci.nsIWritablePropertyBag);
  Assert.equal(
    bestUpdate.unsupported,
    false,
    "The unsupported update has been discarded."
  );
  Assert.equal(
    bestUpdate.appVersion,
    oldAppVersion,
    "Expected the older version to be chosen over the more recent but unsupported."
  );

  stop_httpserver(doTestFinish);
}
+2 −0
Original line number Diff line number Diff line
@@ -59,6 +59,8 @@ reason = "Feature is Firefox-specific and Windows-specific."
["languagePackUpdates.js"]
skip-if = ["socketprocess_networking"] # Bug 1759035

["mixedUnsupported.js"]

["multiUpdate.js"]
skip-if = ["socketprocess_networking"] # Bug 1759035