Bug 1642300 - Remove nsISearchService.hasEngineWithURL. r=daleharvey
authorMark Banner <standard8@mozilla.com>
Fri, 05 Jun 2020 07:40:20 +0000
changeset 534106 af266858e75b9959022382f53f8c2b8d35e8d757
parent 534105 051d7f284389984a96a9b1ed58bb10ddb8a0b733
child 534107 46f8cd8f4972cc9d6051e48edeb3d0dfc424aeaa
push id118143
push usermbanner@mozilla.com
push dateFri, 05 Jun 2020 09:13:40 +0000
treeherderautoland@731578a5ef95 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaleharvey
bugs1642300
milestone79.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 1642300 - Remove nsISearchService.hasEngineWithURL. r=daleharvey Depends on D77650 Differential Revision: https://phabricator.services.mozilla.com/D77651
toolkit/components/search/SearchService.jsm
toolkit/components/search/nsISearchService.idl
toolkit/components/search/tests/xpcshell/test_hasEngineWithURL.js
toolkit/components/search/tests/xpcshell/xpcshell-common.ini
--- a/toolkit/components/search/SearchService.jsm
+++ b/toolkit/components/search/SearchService.jsm
@@ -3315,85 +3315,16 @@ SearchService.prototype = {
 
       processDomain(urlParsingInfo.mainDomain, false);
       SearchStaticData.getAlternateDomains(
         urlParsingInfo.mainDomain
       ).forEach(d => processDomain(d, true));
     }
   },
 
-  /**
-   * Checks to see if any engine has an EngineURL of type SearchUtils.URL_TYPE.SEARCH
-   * for this request-method, template URL, and query params.
-   *
-   * @param {string} method
-   *   The method of the request.
-   * @param {string} template
-   *   The URL template of the request.
-   * @param {object} formData
-   *   Form data associated with the request.
-   * @returns {boolean}
-   *   Returns true if an engine is found.
-   */
-  hasEngineWithURL(method, template, formData) {
-    this._ensureInitialized();
-
-    // Quick helper method to ensure formData filtered/sorted for compares.
-    let getSortedFormData = data => {
-      return data
-        .filter(a => a.name && a.value)
-        .sort((a, b) => {
-          if (a.name > b.name) {
-            return 1;
-          } else if (b.name > a.name) {
-            return -1;
-          } else if (a.value > b.value) {
-            return 1;
-          }
-          return b.value > a.value ? -1 : 0;
-        });
-    };
-
-    // Sanitize method, ensure formData is pre-sorted.
-    let methodUpper = method.toUpperCase();
-    let sortedFormData = getSortedFormData(formData);
-    let sortedFormLength = sortedFormData.length;
-
-    return this._getSortedEngines(false).some(engine => {
-      return engine._urls.some(url => {
-        // Not an engineURL match if type, method, url, #params don't match.
-        if (
-          url.type != SearchUtils.URL_TYPE.SEARCH ||
-          url.method != methodUpper ||
-          url.template != template ||
-          url.params.length != sortedFormLength
-        ) {
-          return false;
-        }
-
-        // Ensure engineURL formData is pre-sorted. Then, we're
-        // not an engineURL match if any queryParam doesn't compare.
-        let sortedParams = getSortedFormData(url.params);
-        for (let i = 0; i < sortedFormLength; i++) {
-          let data = sortedFormData[i];
-          let param = sortedParams[i];
-          if (
-            param.name != data.name ||
-            param.value != data.value ||
-            param.purpose != data.purpose
-          ) {
-            return false;
-          }
-        }
-        // Else we're a match.
-        return true;
-      });
-    });
-  },
-
   parseSubmissionURL(url) {
     if (!gInitialized) {
       // If search is not initialized, do nothing.
       // This allows us to use this function early in telemetry.
       // The only other consumer of this (places) uses it much later.
       return gEmptyParseSubmissionResult;
     }
 
--- a/toolkit/components/search/nsISearchService.idl
+++ b/toolkit/components/search/nsISearchService.idl
@@ -256,33 +256,16 @@ interface nsISearchService : nsISupports
   readonly attribute bool isInitialized;
 
   /**
    * Resets the default engine to its original value.
    */
   Promise resetToOriginalDefaultEngine();
 
   /**
-   * Checks if an EngineURL of type URLTYPE_SEARCH_HTML exists for
-   * any engine, with a matching method, template URL, and query params.
-   *
-   * @param method
-   *        The HTTP request method used when submitting a search query.
-   *        Must be a case insensitive value of either "get" or "post".
-   *
-   * @param url
-   *        The URL to which search queries should be sent.
-   *        Must not be null.
-   *
-   * @param formData
-   *        The un-sorted form data used as query params.
-   */
-  boolean hasEngineWithURL(in AString method, in AString url, in jsval formData);
-
-  /**
    * Adds a new search engine from the file at the supplied URI, optionally
    * asking the user for confirmation first.  If a confirmation dialog is
    * shown, it will offer the option to begin using the newly added engine
    * right away.
    *
    * @param engineURL
    *        The URL to the search engine's description file.
    *
deleted file mode 100644
--- a/toolkit/components/search/tests/xpcshell/test_hasEngineWithURL.js
+++ /dev/null
@@ -1,134 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
-
-/**
- * Tests the hasEngineWithURL() method of the nsISearchService.
- */
-
-// Return a discreet, cloned copy of an (engine) object.
-function getEngineClone(engine) {
-  return JSON.parse(JSON.stringify(engine));
-}
-
-// Check whether and engine does or doesn't exist.
-function checkEngineState(exists, engine) {
-  Assert.equal(
-    exists,
-    Services.search.hasEngineWithURL(
-      engine.method,
-      engine.formURL,
-      engine.queryParams
-    )
-  );
-}
-
-// Add a search engine for testing.
-async function addEngineWithParams(engine) {
-  await Services.search.addEngineWithDetails(engine.name, {
-    method: engine.method,
-    template: engine.formURL,
-  });
-
-  let addedEngine = Services.search.getEngineByName(engine.name);
-  for (let param of engine.queryParams) {
-    addedEngine.addParam(param.name, param.value, null);
-  }
-}
-
-// Main test.
-add_task(async function test_hasEngineWithURL() {
-  info("Setting up test");
-
-  useHttpServer();
-
-  info("Test starting");
-  await AddonTestUtils.promiseStartupManager();
-  await Services.search.init();
-
-  // Setup various Engine definitions for method tests.
-  let UNSORTED_ENGINE = {
-    name: "mySearch Engine",
-    method: "GET",
-    formURL: "https://totallyNotRealSearchEngine.com/",
-    queryParams: [
-      { name: "DDs", value: "38s" },
-      { name: "DCs", value: "39s" },
-      { name: "DDs", value: "39s" },
-      { name: "DDs", value: "38s" },
-      { name: "DDs", value: "37s" },
-      { name: "DDs", value: "38s" },
-      { name: "DEs", value: "38s" },
-      { name: "DCs", value: "38s" },
-      { name: "DEs", value: "37s" },
-    ],
-  };
-
-  // Same as UNSORTED_ENGINE, but sorted.
-  let SORTED_ENGINE = {
-    name: "mySearch Engine",
-    method: "GET",
-    formURL: "https://totallyNotRealSearchEngine.com/",
-    queryParams: [
-      { name: "DCs", value: "38s" },
-      { name: "DCs", value: "39s" },
-      { name: "DDs", value: "37s" },
-      { name: "DDs", value: "38s" },
-      { name: "DDs", value: "38s" },
-      { name: "DDs", value: "38s" },
-      { name: "DDs", value: "39s" },
-      { name: "DEs", value: "37s" },
-      { name: "DEs", value: "38s" },
-    ],
-  };
-
-  // Unique variations of the SORTED_ENGINE.
-  let SORTED_ENGINE_METHOD_CHANGE = getEngineClone(SORTED_ENGINE);
-  SORTED_ENGINE_METHOD_CHANGE.method = "PoST";
-
-  let SORTED_ENGINE_FORMURL_CHANGE = getEngineClone(SORTED_ENGINE);
-  SORTED_ENGINE_FORMURL_CHANGE.formURL = "http://www.ahighrpowr.com/";
-
-  let SORTED_ENGINE_QUERYPARM_CHANGE = getEngineClone(SORTED_ENGINE);
-  SORTED_ENGINE_QUERYPARM_CHANGE.queryParams = [];
-
-  let SORTED_ENGINE_NAME_CHANGE = getEngineClone(SORTED_ENGINE);
-  SORTED_ENGINE_NAME_CHANGE.name += " 2";
-
-  // First ensure neither the unsorted engine, nor the same engine
-  // with a pre-sorted list of query parms matches.
-  checkEngineState(false, UNSORTED_ENGINE);
-  info("The unsorted version of the test engine does not exist.");
-  checkEngineState(false, SORTED_ENGINE);
-  info("The sorted version of the test engine does not exist.");
-
-  // Ensure variations of the engine definition do not match.
-  checkEngineState(false, SORTED_ENGINE_METHOD_CHANGE);
-  checkEngineState(false, SORTED_ENGINE_FORMURL_CHANGE);
-  checkEngineState(false, SORTED_ENGINE_QUERYPARM_CHANGE);
-  info("There are no modified versions of the sorted test engine.");
-
-  // Note that this method doesn't check name variations.
-  checkEngineState(false, SORTED_ENGINE_NAME_CHANGE);
-  info("There is no NAME modified version of the sorted test engine.");
-
-  // Add the unsorted engine and it's queryParams.
-  await addEngineWithParams(UNSORTED_ENGINE);
-  info("The unsorted engine has been added.");
-
-  // Then, ensure we find a match for the unsorted engine, and for the
-  // same engine with a pre-sorted list of query parms.
-  checkEngineState(true, UNSORTED_ENGINE);
-  info("The unsorted version of the test engine now exists.");
-  checkEngineState(true, SORTED_ENGINE);
-  info("The sorted version of the same test engine also now exists.");
-
-  // Ensure variations of the engine definition still do not match.
-  checkEngineState(false, SORTED_ENGINE_METHOD_CHANGE);
-  checkEngineState(false, SORTED_ENGINE_FORMURL_CHANGE);
-  checkEngineState(false, SORTED_ENGINE_QUERYPARM_CHANGE);
-  info("There are still no modified versions of the sorted test engine.");
-
-  // Note that this method still doesn't check name variations.
-  checkEngineState(true, SORTED_ENGINE_NAME_CHANGE);
-  info("There IS now a NAME modified version of the sorted test engine.");
-});
--- a/toolkit/components/search/tests/xpcshell/xpcshell-common.ini
+++ b/toolkit/components/search/tests/xpcshell/xpcshell-common.ini
@@ -15,17 +15,16 @@ skip-if = true # Is confusing
 [test_distribution_unreadable.js]
 skip-if = os == "win" # Windows doesn't have the same sort of permissions management.
 [test_engine_selector_application.js]
 [test_engine_selector_order.js]
 [test_engine_selector_remote_settings.js]
 [test_engine_selector.js]
 [test_engine_set_alias.js]
 [test_engineUpdate.js]
-[test_hasEngineWithURL.js]
 [test_identifiers.js]
 [test_ignorelist_update.js]
 [test_ignorelist.js]
 [test_invalid_engine_from_dir.js]
 [test_json_cache_broken.js]
 [test_json_cache_good.js]
 [test_json_cache_ignorelist.js]
 support-files = data/search_ignorelist.json