Commit 02a187af authored by Mark Banner's avatar Mark Banner
Browse files

Bug 1681048 - Ensure obsolete distribution/langpack engines are dropped in the...

Bug 1681048 - Ensure obsolete distribution/langpack engines are dropped in the search service. r=daleharvey

If an engine is default, the user will be reverted to the application/distribution default.

Differential Revision: https://phabricator.services.mozilla.com/D99114
parent d1065b06
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -1034,6 +1034,27 @@ SearchService.prototype = {
        continue;
      }

      // Some OpenSearch type engines are now obsolete and no longer supported.
      // These were application provided engines that used to use the OpenSearch
      // format before gecko transitioned to WebExtensions.
      // These will sometimes have been missed in migration due to various
      // reasons, and due to how the settings saves everything. We therefore
      // explicitly ignore them here to drop them, and let the rest of the code
      // fallback to the application/distribution default if necessary.
      let loadPath = engineJSON._loadPath?.toLowerCase();
      if (
        loadPath &&
        // Replaced by application provided in Firefox 79.
        (loadPath.startsWith("[distribution]") ||
          // Langpack engines moved in-app in Firefox 62.
          // Note: these may be prefixed by jar:,
          loadPath.includes("[app]/extensions/langpack") ||
          loadPath.includes("[other]/langpack") ||
          loadPath.includes("[profile]/extensions/langpack"))
      ) {
        continue;
      }

      try {
        let engine = new SearchEngine({
          isAppProvided: false,
+43 −0
Original line number Diff line number Diff line
{
  "version": 1,
  "buildID": "20121106",
  "locale": "en-US",
  "metaData": {},
  "engines": [
    {
      "_name": "engine1",
      "_metaData": {
        "alias": "testAlias"
      },
      "_isAppProvided": true
    },
    {
      "_name": "engine2",
      "_metaData": {
        "alias": null,
        "hidden": true
      },
      "_isAppProvided": true
    },
    {
      "_name": "Distribution",
      "_shortName": "distribution",
      "_loadPath": "[distribution]/searchplugins/common/distribution.xml",
      "description": "Distribution Search",
      "__searchForm": null,
      "_metaData": {},
      "_urls": [
        {
          "template": "https://example.com/search",
          "rels": [
            "searchform"
          ],
          "resultDomain": "example.com",
          "params": []
        }
      ],
      "queryCharset": "UTF-8",
      "_readOnly": false
    }
  ]
}
+99 −0
Original line number Diff line number Diff line
{
  "version": 1,
  "buildID": "20121106",
  "locale": "en-US",
  "metaData": {},
  "engines": [
    {
      "_name": "engine1",
      "_metaData": {
        "alias": "testAlias"
      },
      "_isAppProvided": true
    },
    {
      "_name": "engine2",
      "_metaData": {
        "alias": null,
        "hidden": true
      },
      "_isAppProvided": true
    },
    {
      "_name": "Langpack",
      "_shortName": "langpack-ru",
      "_loadPath": "jar:[app]/extensions/langpack-ru@firefox.mozilla.org.xpi!browser/langpack.xml",
      "description": "Langpack search",
      "__searchForm": null,
      "_metaData": {},
      "_urls": [
        {
          "template": "https://example.com/search",
          "rels": [
            "searchform"
          ],
          "resultDomain": "example.com",
          "params": []
        }
      ],
      "queryCharset": "UTF-8"
    },
    {
      "_name": "Langpack1",
      "_shortName": "langpack1-ru",
      "_loadPath": "[app]/extensions/langpack-ru@firefox.mozilla.org.xpi!browser/langpack1.xml",
      "description": "Langpack1 search",
      "__searchForm": null,
      "_metaData": {},
      "_urls": [
        {
          "template": "https://example1.com/search",
          "rels": [
            "searchform"
          ],
          "resultDomain": "example1.com",
          "params": []
        }
      ],
      "queryCharset": "UTF-8"
    },
    {
      "_name": "Langpack2",
      "_shortName": "langpack2-ru",
      "_loadPath": "jar:[profile]/extensions/langpack-ru@firefox.mozilla.org.xpi!browser/langpack2.xml",
      "description": "Langpack2 search",
      "__searchForm": null,
      "_metaData": {},
      "_urls": [
        {
          "template": "https://example2.com/search",
          "rels": [
            "searchform"
          ],
          "resultDomain": "example2.com",
          "params": []
        }
      ],
      "queryCharset": "UTF-8"
    },
    {
      "_name": "Langpack3",
      "_shortName": "langpack3-ru",
      "_loadPath": "jar:[other]/langpack-ru@firefox.mozilla.org.xpi!browser/langpack3.xml",
      "description": "Langpack3 search",
      "__searchForm": null,
      "_metaData": {},
      "_urls": [
        {
          "template": "https://example3.com/search",
          "rels": [
            "searchform"
          ],
          "resultDomain": "example3.com",
          "params": []
        }
      ],
      "queryCharset": "UTF-8"
    }
  ]
}
+83 −0
Original line number Diff line number Diff line
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/*
 * Test removing obsolete engine types on upgrade of settings.
 */

"use strict";

const { getAppInfo } = ChromeUtils.import(
  "resource://testing-common/AppInfo.jsm"
);

async function loadSettingsFile(settingsFile, name) {
  let settings = await readJSONFile(do_get_file(settingsFile));

  settings.metaData.current = name;
  settings.metaData.hash = SearchUtils.getVerificationHash(name);

  await promiseSaveSettingsData(settings);
}

/**
 * Start the search service and confirm the engine properties match the expected values.
 *
 * @param {string} settingsFile
 *   The path to the settings file to use.
 * @param {string} engineName
 *   The engine name that should be default and is being removed.
 */
async function checkLoadSettingProperties(settingsFile, engineName) {
  await loadSettingsFile(settingsFile, engineName);

  const settingsFileWritten = promiseAfterSettings();
  let ss = new SearchService();
  let result = await ss.init();

  Assert.ok(
    Components.isSuccessCode(result),
    "Should have successfully initialized the search service"
  );

  await settingsFileWritten;

  let engines = await ss.getEngines();

  Assert.deepEqual(
    engines.map(e => e.name),
    ["engine1", "engine2"],
    "Should have only loaded the app-provided engines"
  );

  Assert.equal(
    (await Services.search.getDefault()).name,
    "engine1",
    "Should have used the configured default engine"
  );

  removeSettingsFile();
  ss._removeObservers();
}

/**
 * Test reading from search.json.mozlz4
 */
add_task(async function setup() {
  await SearchTestUtils.useTestEngines("data1");
  await AddonTestUtils.promiseStartupManager();
});

add_task(async function test_obsolete_distribution_engine() {
  await checkLoadSettingProperties(
    "data/search-obsolete-distribution.json",
    "Distribution"
  );
});

add_task(async function test_obsolete_langpack_engine() {
  await checkLoadSettingProperties(
    "data/search-obsolete-langpack.json",
    "Langpack"
  );
});
+6 −8
Original line number Diff line number Diff line
@@ -33,11 +33,16 @@ support-files =
  data/engines.json
  data/search.json
  data/search-legacy.json
  data/search-obsolete-distribution.json
  data/search-obsolete-langpack.json
  data/searchSuggestions.sjs
  data/geolookup-extensions/multilocale/favicon.ico
  data/geolookup-extensions/multilocale/manifest.json
  data/geolookup-extensions/multilocale/_locales/af/messages.json
  data/geolookup-extensions/multilocale/_locales/an/messages.json
  data1/engine1/manifest.json
  data1/engine2/manifest.json
  data1/engines.json
  simple-engines/engines.json
  simple-engines/basic/manifest.json
  simple-engines/hidden/manifest.json
@@ -87,10 +92,6 @@ tag = remotesettings searchmain
[test_initialization.js]
[test_list_json_locale.js]
[test_list_json_no_private_default.js]
support-files =
  data1/engine1/manifest.json
  data1/engine2/manifest.json
  data1/engines.json
[test_list_json_searchdefault.js]
[test_list_json_searchorder.js]
[test_maybereloadengine_order.js]
@@ -138,12 +139,9 @@ support-files =
[test_settings_ignorelist.js]
support-files = data/search_ignorelist.json
[test_settings_none.js]
[test_settings_obsolete.js]
[test_settings_persist.js]
[test_settings.js]
support-files =
  data1/engine1/manifest.json
  data1/engine2/manifest.json
  data1/engines.json
[test_sort_orders-no-hints.js]
[test_sort_orders.js]
[test_validate_engines.js]