Commit 0d43637d authored by Sandor Molnar's avatar Sandor Molnar Committed by smolnar@mozilla.com
Browse files

Revert "Bug 1967273 - Reject clearCacheForExtensionPrincipal when application...

Revert "Bug 1967273 - Reject clearCacheForExtensionPrincipal when application shutdown is already initiated. r=willdurand" for causing Mn failures.

This reverts commit a56c3cd3.

Revert "Bug 1964408 - Add additional test coverage for stale/missing xpistate with system-signed updates installed. r=willdurand"

This reverts commit 6c7851b7.

Revert "Bug 1964408 - Scan application scopes early on startup if expected app-system-builtins entries are missing from the addonStartup.json.lz4 data. r=willdurand"

This reverts commit 6121e746.

Revert "Bug 1964408 - Scan application scopes early on startup if app-builtin-addons location is missing from addonStartup.json.lz4 data. r=baku,willdurand"

This reverts commit e799258b.
parent 02887be1
Loading
Loading
Loading
Loading
+0 −8
Changes for toolkit/components/extensions/Extension.sys.mjs: 0 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -443,14 +443,6 @@ function clearCacheForExtensionPrincipal(principal, clearAll = false) {
    return Promise.reject(new Error("Unexpected non extension principal"));
  }

  if (Services.startup.shuttingDown) {
    return Promise.reject(
      new Error(
        `clearCacheForExtensionPrincipal called after shutdown was initiated`
      )
    );
  }

  // TODO(Bug 1750053): replace the two specific flags with a "clear all caches one"
  // (along with covering the other kind of cached data with tests).
  const clearDataFlags = clearAll
+0 −25
Changes for toolkit/mozapps/extensions/internal/XPIProvider.sys.mjs: 0 added lines, 25 removed lines.
Original line number Diff line number Diff line
@@ -1521,31 +1521,6 @@ var XPIStates = {
      startupScanScopes = AddonManager.SCOPE_ALL;
    }

    // Restrict logic to detect if the app-builtin-addons XPIStates location data is missing,
    // corrupted or stale to the first XPIStates.scanForChanges call originated early on the
    // XPIProvider startup (and skip it on further calls that may be originated later on, e.g.
    // when we are checking for new sideloaded extensions after the application is fully started).
    if (shouldRestoreLocationData) {
      if (!oldLocations.has(KEY_APP_SYSTEM_BUILTINS)) {
        logger.warn(
          `Force scan SCOPE_APPLICATION (${KEY_APP_SYSTEM_BUILTINS} location missing from XPIStates)`
        );
        startupScanScopes |= AddonManager.SCOPE_APPLICATION;
      } else {
        const knownIds = new Set(
          Object.keys(oldState[KEY_APP_SYSTEM_BUILTINS].addons ?? {})
        );
        const expectedIds = new Set(SystemBuiltInLocation.readAddons().keys());
        const missingIds = expectedIds.difference(knownIds);
        if (missingIds.size) {
          logger.warn(
            `Force scan SCOPE_APPLICATION location (detected missing builtins: ${JSON.stringify(Array.from(missingIds))})`
          );
          startupScanScopes |= AddonManager.SCOPE_APPLICATION;
        }
      }
    }

    for (let loc of XPIStates.locations()) {
      oldLocations.delete(loc.name);

+0 −191
Changes for toolkit/mozapps/extensions/test/xpcshell/test_system_builtins.js: 0 added lines, 191 removed lines.
Original line number Diff line number Diff line
@@ -162,194 +162,3 @@ add_task(
    await promiseShutdownManager();
  }
);

async function testBrokenXPIStates({
  description,
  setupTestCase,
  expectSystemUpdateVersion,
}) {
  info(`Enter test case (${description})`);
  const builtins = [0, 1, 2].map(i => ({
    addon_id: `system${i}@tests.mozilla.org`,
    addon_version: "1.1",
    res_url: `resource://builtin-addon${i}/`,
  }));
  await Promise.all(
    builtins.map(({ addon_id, addon_version }, i) =>
      setupBuiltinExtension(
        {
          manifest: {
            name: `Built-In System Add-on ${i}`,
            version: addon_version,
            browser_specific_settings: {
              gecko: { id: addon_id },
            },
          },
        },
        `builtin-addon${i}`
      )
    )
  );
  AddonTestUtils.updateAppInfo(appInfoInitial);
  await overrideBuiltIns({ builtins });
  const createBuiltinAddonsStartedPromises = () =>
    builtins.map(({ addon_id }) => {
      const msg = `Await ${addon_id} startup`;
      const promise = promiseWebExtensionStartup(addon_id);
      return async () => {
        info(msg);
        await promise;
      };
    });
  let builtinAddonsStartedPromises = createBuiltinAddonsStartedPromises();

  info(`Initialize test case profile`);
  await promiseStartupManager();
  for (const waitForBuiltinStartup of builtinAddonsStartedPromises) {
    await waitForBuiltinStartup();
  }

  const updatedBuiltinAddonId = builtins[2].addon_id;
  async function verifyUpdatedBuiltinAddon() {
    let updatedBuiltinAddon = await AddonManager.getAddonByID(
      updatedBuiltinAddonId
    );
    Assert.equal(
      updatedBuiltinAddon.version,
      "2.0",
      `Got the expected version for the updated builtin addon ${updatedBuiltinAddonId}`
    );
    Assert.equal(
      updatedBuiltinAddon.locationName,
      "app-system-addons",
      `Got the expected locationName for the updated builtin addon ${updatedBuiltinAddonId}`
    );
  }

  info(`Install system-signed update for ${updatedBuiltinAddonId}`);
  const oldUsePrivilegedSignature = (AddonTestUtils.usePrivilegedSignatures =
    () => "system");
  let xpi = AddonTestUtils.createTempWebExtensionFile({
    manifest: {
      version: "2.0",
      browser_specific_settings: {
        gecko: { id: updatedBuiltinAddonId },
      },
    },
  });
  AddonTestUtils.usePrivilegedSignatures = oldUsePrivilegedSignature;
  let xml = buildSystemAddonUpdates([
    {
      id: updatedBuiltinAddonId,
      version: "2.0",
      path: xpi.leafName,
      xpi,
    },
  ]);
  await installSystemAddons(xml, [updatedBuiltinAddonId]);
  await verifyUpdatedBuiltinAddon();
  await promiseShutdownManager();
  ok(
    AddonTestUtils.addonStartup.exists(),
    "Expect addonStartup.json.lz4 file to exist"
  );

  info(`Setup test case (${description})`);
  // Run callback to mimic the specific test scenario).
  await setupTestCase();
  info(`Startup addon manager again (${description})`);

  builtinAddonsStartedPromises = createBuiltinAddonsStartedPromises();

  await overrideBuiltIns({ builtins });
  await promiseStartupManager();
  for (const waitForBuiltinStartup of builtinAddonsStartedPromises) {
    await waitForBuiltinStartup();
  }
  // Verify the updated system addon is the one enabled.
  if (expectSystemUpdateVersion) {
    await verifyUpdatedBuiltinAddon();
  }
  // Clean updated system addon.
  await installSystemAddons(buildSystemAddonUpdates([]), []);
  await promiseShutdownManager();
  info(`Exit test case (${description})`);
}

// This tests case verifies that in case of a missing or completely corrupted
// xpi states, the builin addons are still installed and started up as expected.
add_task(
  {
    pref_set: [
      ["extensions.skipInstallDefaultThemeForTests", true],
      // Set the same startupScanScopes value set by default on a Firefox Desktop
      // instance.
      ["extensions.startupScanScopes", 0],
    ],
  },
  async function test_missing_xpistate() {
    await testBrokenXPIStates({
      description: "missing addonStartup.json.lz4",
      async setupTestCase() {
        await IOUtils.remove(AddonTestUtils.addonStartup.path);
        ok(
          !AddonTestUtils.addonStartup.exists(),
          "Expect addonStartup.json.lz4 file to be removed"
        );
      },
      // TODO(Bug 1966736): set to true along with the changes needed to make sure
      // the system-signed updated versions to built-in add-ons are the ones
      // activated on regular Firefox startups (startups without application
      // version changes) when the system-addons location data from
      // addonStartup.json.lz4 is lost or stale.
      expectSystemUpdateVersion: false,
    });
  }
);

// This tests case verifies that in case of a stale addonStartup.json.lz4 state,
// missing builtin addons are still detected early during application startup and
// installed and started as expected.
add_task(
  {
    pref_set: [
      ["extensions.skipInstallDefaultThemeForTests", true],
      // Set the same startupScanScopes value set by default on a Firefox Desktop
      // instance.
      ["extensions.startupScanScopes", 0],
    ],
  },
  async function test_stale_xpistate() {
    async function setupTestCase() {
      const { JSONFile } = ChromeUtils.importESModule(
        "resource://gre/modules/JSONFile.sys.mjs"
      );
      const aomStartup = Cc[
        "@mozilla.org/addons/addon-manager-startup;1"
      ].getService(Ci.amIAddonManagerStartup);
      const xpiStateData = aomStartup.readStartupData();
      ok(
        xpiStateData["app-builtin-addons"],
        "Got app-builtin-addons location in the XPIStates data"
      );
      const builtinId = "system2@tests.mozilla.org";
      ok(
        xpiStateData["app-builtin-addons"]?.addons?.[builtinId],
        `Got ${builtinId} entry in XPIStates data`
      );
      delete xpiStateData["app-builtin-addons"].addons[builtinId];
      let jsonFile = new JSONFile({
        path: PathUtils.join(AddonTestUtils.addonStartup.path),
        compression: "lz4",
      });
      jsonFile.data = xpiStateData;
      await jsonFile._save();
    }
    await testBrokenXPIStates({
      description:
        "stale addonStartup.json.lz4 missing one of the builtin addons",
      setupTestCase,
      expectSystemUpdateVersion: true,
    });
  }
);