Bug 1405670 - Fix search service tests relying on dropping .xml files in the profile folder. r=adw, a=sledru
authorFlorian Quèze <florian@queze.net>
Fri, 17 Nov 2017 12:05:47 +0100
changeset 444880 1922cbee6cf4e5b7756423babdd48bfe5b98c949
parent 444879 e4307e3d7f1f5f3b378f8fbc3a6b1458f8ed1f23
child 444881 827c49cd8d4076a30d07dbf2f99b65839dc6f15a
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw, sledru
bugs1405670
milestone58.0
Bug 1405670 - Fix search service tests relying on dropping .xml files in the profile folder. r=adw, a=sledru
toolkit/components/search/tests/xpcshell/head_search.js
toolkit/components/search/tests/xpcshell/test_async_addon.js
toolkit/components/search/tests/xpcshell/test_async_profile_engine.js
toolkit/components/search/tests/xpcshell/test_geodefaults.js
toolkit/components/search/tests/xpcshell/test_identifiers.js
toolkit/components/search/tests/xpcshell/test_location.js
toolkit/components/search/tests/xpcshell/test_location_error.js
toolkit/components/search/tests/xpcshell/test_location_funnelcake.js
toolkit/components/search/tests/xpcshell/test_location_malformed_json.js
toolkit/components/search/tests/xpcshell/test_location_migrate_countrycode_isUS.js
toolkit/components/search/tests/xpcshell/test_location_migrate_no_countrycode_isUS.js
toolkit/components/search/tests/xpcshell/test_location_migrate_no_countrycode_notUS.js
toolkit/components/search/tests/xpcshell/test_location_partner.js
toolkit/components/search/tests/xpcshell/test_location_sync.js
toolkit/components/search/tests/xpcshell/test_location_timeout.js
toolkit/components/search/tests/xpcshell/test_location_timeout_xhr.js
toolkit/components/search/tests/xpcshell/test_remove_profile_engine.js
toolkit/components/search/tests/xpcshell/test_searchReset.js
toolkit/components/search/tests/xpcshell/test_selectedEngine.js
toolkit/components/search/tests/xpcshell/test_sync_addon.js
toolkit/components/search/tests/xpcshell/test_sync_profile_engine.js
--- a/toolkit/components/search/tests/xpcshell/head_search.js
+++ b/toolkit/components/search/tests/xpcshell/head_search.js
@@ -58,22 +58,16 @@ function dumpn(text) {
  * chrome://testsearchplugin/locale/searchplugins/
  */
 function configureToLoadJarEngines() {
   let url = "chrome://testsearchplugin/locale/searchplugins/";
   let resProt = Services.io.getProtocolHandler("resource")
                         .QueryInterface(Ci.nsIResProtocolHandler);
   resProt.setSubstitution("search-plugins",
                           Services.io.newURI(url));
-
-  // Ensure a test engine exists in the app dir anyway.
-  let dir = Services.dirsvc.get(NS_APP_SEARCH_DIR, Ci.nsIFile);
-  if (!dir.exists())
-    dir.create(dir.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
-  do_get_file("data/engine-app.xml").copyTo(dir, "app.xml");
 }
 
 /**
  * Fake the installation of an add-on in the profile, by creating the
  * directory and registering it with the directory service.
  */
 function installAddonEngine(name = "engine-addon") {
   const XRE_EXTENSIONS_DIR_LIST = "XREExtDL";
@@ -408,33 +402,20 @@ var addTestEngines = async function(aIte
 
   return engines;
 };
 
 /**
  * Installs a test engine into the test profile.
  */
 function installTestEngine() {
-  removeMetadata();
-  removeCacheFile();
-
-  do_check_false(Services.search.isInitialized);
-
-  let engineDummyFile = gProfD.clone();
-  engineDummyFile.append("searchplugins");
-  engineDummyFile.append("test-search-engine.xml");
-  let engineDir = engineDummyFile.parent;
-  engineDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
-
-  do_get_file("data/engine.xml").copyTo(engineDir, "engine.xml");
-
-  do_register_cleanup(function() {
-    removeMetadata();
-    removeCacheFile();
-  });
+  useHttpServer();
+  return addTestEngines([
+    { name: kTestEngineName, xmlFileName: "engine.xml" },
+  ]);
 }
 
 /**
  * Set a localized preference on the default branch
  * @param aPrefName
  *        The name of the pref to set.
  */
 function setLocalizedDefaultPref(aPrefName, aValue) {
@@ -443,42 +424,26 @@ function setLocalizedDefaultPref(aPrefNa
           .setCharPref(aPrefName, value);
 }
 
 
 /**
  * Installs two test engines, sets them as default for US vs. general.
  */
 function setUpGeoDefaults() {
-  removeMetadata();
-  removeCacheFile();
-
-  do_check_false(Services.search.isInitialized);
-
-  let engineDummyFile = gProfD.clone();
-  engineDummyFile.append("searchplugins");
-  engineDummyFile.append("test-search-engine.xml");
-  let engineDir = engineDummyFile.parent;
-  engineDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
-
-  do_get_file("data/engine.xml").copyTo(engineDir, "engine.xml");
-
-  engineDummyFile = gProfD.clone();
-  engineDummyFile.append("searchplugins");
-  engineDummyFile.append("test-search-engine2.xml");
-
-  do_get_file("data/engine2.xml").copyTo(engineDir, "engine2.xml");
+  const kSecondTestEngineName = "A second test engine";
 
   setLocalizedDefaultPref("defaultenginename", "Test search engine");
   setLocalizedDefaultPref("defaultenginename.US", "A second test engine");
 
-  do_register_cleanup(function() {
-    removeMetadata();
-    removeCacheFile();
-  });
+  useHttpServer();
+  return addTestEngines([
+    { name: kTestEngineName, xmlFileName: "engine.xml" },
+    { name: kSecondTestEngineName, xmlFileName: "engine2.xml" },
+  ]);
 }
 
 /**
  * Returns a promise that is resolved when an observer notification from the
  * search service fires with the specified data.
  *
  * @param aExpectedData
  *        The value the observer notification sends that causes us to resolve
--- a/toolkit/components/search/tests/xpcshell/test_async_addon.js
+++ b/toolkit/components/search/tests/xpcshell/test_async_addon.js
@@ -13,21 +13,16 @@ function run_test() {
   installAddonEngine();
 
   do_check_false(Services.search.isInitialized);
 
   Services.search.init(function search_initialized(aStatus) {
     do_check_true(Components.isSuccessCode(aStatus));
     do_check_true(Services.search.isInitialized);
 
-    // test the add-on engine is loaded in addition to our jar engine
+    // test the legacy add-on engine is _not_ loaded
     let engines = Services.search.getEngines();
-    do_check_eq(engines.length, 2);
-
-    // test jar engine is loaded ok.
-    let engine = Services.search.getEngineByName("addon");
-    do_check_neq(engine, null);
-
-    do_check_eq(engine.description, "addon");
+    do_check_eq(engines.length, 1);
+    do_check_eq(Services.search.getEngineByName("addon"), null);
 
     do_test_finished();
   });
 }
--- a/toolkit/components/search/tests/xpcshell/test_async_profile_engine.js
+++ b/toolkit/components/search/tests/xpcshell/test_async_profile_engine.js
@@ -1,27 +1,26 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-const NS_APP_USER_SEARCH_DIR  = "UsrSrchPlugns";
-
 function run_test() {
   do_test_pending();
 
   removeMetadata();
   removeCacheFile();
 
   do_load_manifest("data/chrome.manifest");
 
   configureToLoadJarEngines();
 
-  // Copy an engine in [profile]/searchplugin/ and ensure it's not
+  // Copy an engine in [profile]/searchplugins/ and ensure it's not
   // overriding the same file from a jar.
   // The description in the file we are copying is 'profile'.
-  let dir = Services.dirsvc.get(NS_APP_USER_SEARCH_DIR, Ci.nsIFile);
+  let dir = gProfD.clone();
+  dir.append("searchplugins");
   if (!dir.exists())
     dir.create(dir.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
   do_get_file("data/engine-override.xml").copyTo(dir, "bug645970.xml");
 
   do_check_false(Services.search.isInitialized);
 
   Services.search.init(function search_initialized(aStatus) {
     do_check_true(Components.isSuccessCode(aStatus));
--- a/toolkit/components/search/tests/xpcshell/test_geodefaults.js
+++ b/toolkit/components/search/tests/xpcshell/test_geodefaults.js
@@ -7,18 +7,16 @@ var requests = [];
 var gServerCohort = "";
 
 const kUrlPref = "geoSpecificDefaults.url";
 
 const kDayInSeconds = 86400;
 const kYearInSeconds = kDayInSeconds * 365;
 
 function run_test() {
-  installTestEngine();
-
   let srv = new HttpServer();
 
   srv.registerPathHandler("/lookup_defaults", (metadata, response) => {
     response.setStatusLine("1.1", 200, "OK");
     let data = {interval: kYearInSeconds,
                 settings: {searchDefault: "Test search engine"}};
     if (gServerCohort)
       data.cohort = gServerCohort;
@@ -63,16 +61,20 @@ function checkRequest(cohort = "") {
 
 add_task(async function no_request_if_prefed_off() {
   // Disable geoSpecificDefaults and check no HTTP request is made.
   Services.prefs.setBoolPref("browser.search.geoSpecificDefaults", false);
   await asyncInit();
   checkNoRequest();
   await promiseAfterCache();
 
+  // Install kTestEngineName and wait for it to reach the disk.
+  await installTestEngine();
+  await promiseAfterCache();
+
   // The default engine should be set based on the prefs.
   do_check_eq(Services.search.currentEngine.name, getDefaultEngineName(false));
 
   // Ensure nothing related to geoSpecificDefaults has been written in the metadata.
   let metadata = await promiseGlobalMetadata();
   do_check_eq(typeof metadata.searchDefaultExpir, "undefined");
   do_check_eq(typeof metadata.searchDefault, "undefined");
   do_check_eq(typeof metadata.searchDefaultHash, "undefined");
--- a/toolkit/components/search/tests/xpcshell/test_identifiers.js
+++ b/toolkit/components/search/tests/xpcshell/test_identifiers.js
@@ -15,30 +15,22 @@ function run_test() {
   do_load_manifest("data/chrome.manifest");
 
   configureToLoadJarEngines();
 
   run_next_test();
 }
 
 add_test(function test_identifier() {
-  let engineFile = gProfD.clone();
-  engineFile.append("searchplugins");
-  engineFile.append("test-search-engine.xml");
-  engineFile.parent.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
-
-  // Copy the test engine to the test profile.
-  let engineTemplateFile = do_get_file("data/engine.xml");
-  engineTemplateFile.copyTo(engineFile.parent, "test-search-engine.xml");
-
-  Services.search.init(function initComplete(aResult) {
+  Services.search.init(async function initComplete(aResult) {
     do_print("init'd search service");
     do_check_true(Components.isSuccessCode(aResult));
 
-    let profileEngine = Services.search.getEngineByName("Test search engine");
+    await installTestEngine();
+    let profileEngine = Services.search.getEngineByName(kTestEngineName);
     let jarEngine = Services.search.getEngineByName("bug645970");
 
     do_check_true(profileEngine instanceof Ci.nsISearchEngine);
     do_check_true(jarEngine instanceof Ci.nsISearchEngine);
 
     // An engine loaded from the profile directory won't have an identifier,
     // because it's not built-in.
     do_check_eq(profileEngine.identifier, null);
--- a/toolkit/components/search/tests/xpcshell/test_location.js
+++ b/toolkit/components/search/tests/xpcshell/test_location.js
@@ -1,14 +1,12 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 function run_test() {
-  installTestEngine();
-
   Services.prefs.setCharPref("browser.search.geoip.url", 'data:application/json,{"country_code": "AU"}');
   Services.search.init(() => {
     equal(Services.prefs.getCharPref("browser.search.countryCode"), "AU", "got the correct country code.");
     equal(Services.prefs.getCharPref("browser.search.region"), "AU", "region pref also set to the countryCode.");
     // No isUS pref is ever written
     ok(!Services.prefs.prefHasUserValue("browser.search.isUS"), "no isUS pref");
     // check we have "success" recorded in telemetry
     checkCountryResultTelemetry(TELEMETRY_RESULT_ENUM.SUCCESS);
--- a/toolkit/components/search/tests/xpcshell/test_location_error.js
+++ b/toolkit/components/search/tests/xpcshell/test_location_error.js
@@ -1,14 +1,12 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 function run_test() {
-  installTestEngine();
-
   // We use an invalid port that parses but won't open
   let url = "http://localhost:0";
 
   Services.prefs.setCharPref("browser.search.geoip.url", url);
   Services.search.init(() => {
     try {
       Services.prefs.getCharPref("browser.search.countryCode");
       ok(false, "not expecting countryCode to be set");
--- a/toolkit/components/search/tests/xpcshell/test_location_funnelcake.js
+++ b/toolkit/components/search/tests/xpcshell/test_location_funnelcake.js
@@ -1,17 +1,13 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-function run_test() {
+add_task(async function run_test() {
   Services.prefs.setCharPref("browser.search.geoip.url", 'data:application/json,{"country_code": "US"}');
   // funnelcake builds start with "mozilla"
   Services.prefs.setCharPref("distribution.id", "mozilla38");
-  setUpGeoDefaults();
-
-  Services.search.init(() => {
-    equal(Services.search.defaultEngine.name, "A second test engine");
 
-    do_test_finished();
-    run_next_test();
-  });
-  do_test_pending();
-}
+  await setUpGeoDefaults();
+  await asyncReInit();
+
+  equal(Services.search.defaultEngine.name, "A second test engine");
+});
--- a/toolkit/components/search/tests/xpcshell/test_location_malformed_json.js
+++ b/toolkit/components/search/tests/xpcshell/test_location_malformed_json.js
@@ -13,18 +13,16 @@ function promiseTimezoneMessage() {
         }
       }
     };
     Services.console.registerListener(listener);
   });
 }
 
 function run_test() {
-  installTestEngine();
-
   // setup a console listener for the timezone fallback message.
   let promiseTzMessage = promiseTimezoneMessage();
 
   // Here we have malformed JSON
   Services.prefs.setCharPref("browser.search.geoip.url", 'data:application/json,{"country_code"');
   Services.search.init(() => {
     ok(!Services.prefs.prefHasUserValue("browser.search.countryCode"), "should be no countryCode pref");
     ok(!Services.prefs.prefHasUserValue("browser.search.region"), "should be no region pref");
--- a/toolkit/components/search/tests/xpcshell/test_location_migrate_countrycode_isUS.js
+++ b/toolkit/components/search/tests/xpcshell/test_location_migrate_countrycode_isUS.js
@@ -1,16 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // Here we are testing the "migration" when both isUS and countryCode are
 // set.
 function run_test() {
-  installTestEngine();
-
   // Set the prefs we care about.
   Services.prefs.setBoolPref("browser.search.isUS", true);
   Services.prefs.setCharPref("browser.search.countryCode", "US");
   // And the geoip request that will return AU - it shouldn't be used.
   Services.prefs.setCharPref("browser.search.geoip.url", 'data:application/json,{"country_code": "AU"}');
   Services.search.init(() => {
     // "region" and countryCode should still reflect US.
     equal(Services.prefs.getCharPref("browser.search.region"), "US", "got the correct region.");
--- a/toolkit/components/search/tests/xpcshell/test_location_migrate_no_countrycode_isUS.js
+++ b/toolkit/components/search/tests/xpcshell/test_location_migrate_no_countrycode_isUS.js
@@ -1,16 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // Here we are testing the "migration" from the isUS pref being true but when
 // no country-code exists.
 function run_test() {
-  installTestEngine();
-
   // Set the pref we care about.
   Services.prefs.setBoolPref("browser.search.isUS", true);
   // And the geoip request that will return *not* US.
   Services.prefs.setCharPref("browser.search.geoip.url", 'data:application/json,{"country_code": "AU"}');
   Services.search.init(() => {
     // "region" should be set to US, but countryCode to AU.
     equal(Services.prefs.getCharPref("browser.search.region"), "US", "got the correct region.");
     equal(Services.prefs.getCharPref("browser.search.countryCode"), "AU", "got the correct country code.");
--- a/toolkit/components/search/tests/xpcshell/test_location_migrate_no_countrycode_notUS.js
+++ b/toolkit/components/search/tests/xpcshell/test_location_migrate_no_countrycode_notUS.js
@@ -1,16 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // Here we are testing the "migration" from the isUS pref being false but when
 // no country-code exists.
 function run_test() {
-  installTestEngine();
-
   // Set the pref we care about.
   Services.prefs.setBoolPref("browser.search.isUS", false);
   // And the geoip request that will return US.
   Services.prefs.setCharPref("browser.search.geoip.url", 'data:application/json,{"country_code": "US"}');
   Services.search.init(() => {
     // "region" and countryCode should reflect US.
     equal(Services.prefs.getCharPref("browser.search.region"), "US", "got the correct region.");
     equal(Services.prefs.getCharPref("browser.search.countryCode"), "US", "got the correct country code.");
--- a/toolkit/components/search/tests/xpcshell/test_location_partner.js
+++ b/toolkit/components/search/tests/xpcshell/test_location_partner.js
@@ -1,16 +1,12 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-function run_test() {
+add_task(async function run_test() {
   Services.prefs.setCharPref("browser.search.geoip.url", 'data:application/json,{"country_code": "US"}');
   Services.prefs.setCharPref("distribution.id", "partner-1");
-  setUpGeoDefaults();
-
-  Services.search.init(() => {
-    equal(Services.search.defaultEngine.name, "Test search engine");
 
-    do_test_finished();
-    run_next_test();
-  });
-  do_test_pending();
-}
+  await setUpGeoDefaults();
+  await asyncReInit();
+
+  equal(Services.search.defaultEngine.name, "Test search engine");
+});
--- a/toolkit/components/search/tests/xpcshell/test_location_sync.js
+++ b/toolkit/components/search/tests/xpcshell/test_location_sync.js
@@ -28,22 +28,16 @@ function promiseTimezoneMessage() {
           resolve(msg);
         }
       }
     };
     Services.console.registerListener(listener);
   });
 }
 
-function run_test() {
-  installTestEngine();
-
-  run_next_test();
-}
-
 // Force a sync init and ensure the right thing happens (ie, that no xhr
 // request is made and we fall back to the timezone-only trick)
 add_task(async function test_simple() {
   deepEqual(getCountryCodePref(), undefined, "no countryCode pref");
   deepEqual(getIsUSPref(), undefined, "no isUS pref");
 
   // Still set a geoip pref so we can (indirectly) check it wasn't used.
   Services.prefs.setCharPref("browser.search.geoip.url", 'data:application/json,{"country_code": "AU"}');
--- a/toolkit/components/search/tests/xpcshell/test_location_timeout.js
+++ b/toolkit/components/search/tests/xpcshell/test_location_timeout.js
@@ -23,18 +23,16 @@ function startServer(continuePromise) {
 }
 
 function getProbeSum(probe, sum) {
   let histogram = Services.telemetry.getHistogramById(probe);
   return histogram.snapshot().sum;
 }
 
 function run_test() {
-  installTestEngine();
-
   let resolveContinuePromise;
   let continuePromise = new Promise(resolve => {
     resolveContinuePromise = resolve;
   });
 
   let server = startServer(continuePromise);
   let url = "http://localhost:" + server.identity.primaryPort + "/lookup_country";
   Services.prefs.setCharPref("browser.search.geoip.url", url);
--- a/toolkit/components/search/tests/xpcshell/test_location_timeout_xhr.js
+++ b/toolkit/components/search/tests/xpcshell/test_location_timeout_xhr.js
@@ -25,18 +25,16 @@ function startServer(continuePromise) {
 
 function verifyProbeSum(probe, sum) {
   let histogram = Services.telemetry.getHistogramById(probe);
   let snapshot = histogram.snapshot();
   equal(snapshot.sum, sum, probe);
 }
 
 function run_test() {
-  installTestEngine();
-
   let resolveContinuePromise;
   let continuePromise = new Promise(resolve => {
     resolveContinuePromise = resolve;
   });
 
   let server = startServer(continuePromise);
   let url = "http://localhost:" + server.identity.primaryPort + "/lookup_country";
   Services.prefs.setCharPref("browser.search.geoip.url", url);
--- a/toolkit/components/search/tests/xpcshell/test_remove_profile_engine.js
+++ b/toolkit/components/search/tests/xpcshell/test_remove_profile_engine.js
@@ -1,35 +1,45 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-const NS_APP_USER_SEARCH_DIR  = "UsrSrchPlugns";
-
-function run_test() {
-  do_test_pending();
-
+add_task(async function run_test() {
   // Copy an engine to [profile]/searchplugin/
-  let dir = Services.dirsvc.get(NS_APP_USER_SEARCH_DIR, Ci.nsIFile);
+  let dir = gProfD.clone();
+  dir.append("searchplugins");
   if (!dir.exists())
     dir.create(dir.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
   do_get_file("data/engine-override.xml").copyTo(dir, "bug645970.xml");
 
   let file = dir.clone();
   file.append("bug645970.xml");
   do_check_true(file.exists());
 
-  do_check_false(Services.search.isInitialized);
+  await asyncInit();
 
-  Services.search.init(function search_initialized(aStatus) {
-    do_check_true(Components.isSuccessCode(aStatus));
-    do_check_true(Services.search.isInitialized);
+  // Install the same engine through a supported way.
+  useHttpServer();
+  await addTestEngines([
+    { name: "bug645970", xmlFileName: "engine-override.xml" },
+  ]);
+  await promiseAfterCache();
+  let data = await promiseCacheData();
 
-    // test the engine is loaded ok.
-    let engine = Services.search.getEngineByName("bug645970");
-    do_check_neq(engine, null);
+  // Put the filePath inside the cache file, to simulate what a pre-58 version
+  // of Firefox would have done.
+  for (let engine of data.engines) {
+    if (engine._name == "bug645970") {
+      engine.filePath = file.path;
+    }
+  }
+
+  await promiseSaveCacheData(data);
 
-    // remove the engine and verify the file has been removed too.
-    Services.search.removeEngine(engine);
-    do_check_false(file.exists());
+  await asyncReInit();
 
-    do_test_finished();
-  });
-}
+  // test the engine is loaded ok.
+  let engine = Services.search.getEngineByName("bug645970");
+  do_check_neq(engine, null);
+
+  // remove the engine and verify the file has been removed too.
+  Services.search.removeEngine(engine);
+  do_check_false(file.exists());
+});
--- a/toolkit/components/search/tests/xpcshell/test_searchReset.js
+++ b/toolkit/components/search/tests/xpcshell/test_searchReset.js
@@ -1,57 +1,48 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-const NS_APP_USER_SEARCH_DIR  = "UsrSrchPlugns";
-
-const kTestEngineShortName = "engine";
+const kTestEngineShortName = "test-search-engine";
 const kWhiteListPrefName = "reset.whitelist";
 
-function run_test() {
-  // Copy an engine to [profile]/searchplugin/
-  let dir = Services.dirsvc.get(NS_APP_USER_SEARCH_DIR, Ci.nsIFile);
-  if (!dir.exists())
-    dir.create(dir.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
-  do_get_file("data/engine.xml").copyTo(dir, kTestEngineShortName + ".xml");
-
-  let file = dir.clone();
-  file.append(kTestEngineShortName + ".xml");
-  do_check_true(file.exists());
-
-  do_check_false(Services.search.isInitialized);
-
+add_task(async function run_test() {
   Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF)
           .setBoolPref("reset.enabled", true);
 
-  run_next_test();
-}
+  await asyncInit();
+  await promiseAfterCache();
+
+  // Install kTestEngineName and wait for it to reach the disk.
+  await installTestEngine();
+  await promiseAfterCache();
+
+  // Simulate an engine found in the profile directory and imported
+  // by a previous version of Firefox.
+  await removeLoadPathHash();
+});
 
 async function removeLoadPathHash() {
   // Remove the loadPathHash and re-initialize the search service.
   let cache = await promiseCacheData();
   for (let engine of cache.engines) {
     if (engine._shortName == kTestEngineShortName) {
       delete engine._metaData.loadPathHash;
       break;
     }
   }
   await promiseSaveCacheData(cache);
   await asyncReInit();
 }
 
 add_task(async function test_no_prompt_when_valid_loadPathHash() {
-  await asyncInit();
-
   // test the engine is loaded ok.
   let engine = Services.search.getEngineByName(kTestEngineName);
   do_check_neq(engine, null);
 
-  await promiseAfterCache();
-
   // The test engine has been found in the profile directory and imported,
   // so it shouldn't have a loadPathHash.
   let metadata = await promiseEngineMetadata();
   do_check_true(kTestEngineShortName in metadata);
   do_check_false("loadPathHash" in metadata[kTestEngineShortName]);
 
   // After making it the currentEngine with the search service API,
   // the test engine should have a valid loadPathHash.
--- a/toolkit/components/search/tests/xpcshell/test_selectedEngine.js
+++ b/toolkit/components/search/tests/xpcshell/test_selectedEngine.js
@@ -3,16 +3,17 @@
 
 Components.utils.import("resource://gre/modules/osfile.jsm");
 
 const kSelectedEnginePref = "browser.search.selectedEngine";
 
 // Check that the default engine matches the defaultenginename pref
 add_task(async function test_defaultEngine() {
   await asyncInit();
+  await installTestEngine();
 
   do_check_eq(Services.search.currentEngine.name, getDefaultEngineName());
 });
 
 // Giving prefs a user value shouldn't change the selected engine.
 add_task(async function test_selectedEngine() {
   let defaultEngineName = getDefaultEngineName();
   // Test the selectedEngine pref.
--- a/toolkit/components/search/tests/xpcshell/test_sync_addon.js
+++ b/toolkit/components/search/tests/xpcshell/test_sync_addon.js
@@ -7,20 +7,14 @@ function run_test() {
 
   do_load_manifest("data/chrome.manifest");
 
   configureToLoadJarEngines();
   installAddonEngine();
 
   do_check_false(Services.search.isInitialized);
 
-  // test the add-on engine is loaded in addition to our jar engine
+  // test the legacy add-on engine is _not_ loaded
   let engines = Services.search.getEngines();
-  do_check_eq(engines.length, 2);
-
   do_check_true(Services.search.isInitialized);
-
-  // test jar engine is loaded ok.
-  let engine = Services.search.getEngineByName("addon");
-  do_check_neq(engine, null);
-
-  do_check_eq(engine.description, "addon");
+  do_check_eq(engines.length, 1);
+  do_check_eq(Services.search.getEngineByName("addon"), null);
 }
--- a/toolkit/components/search/tests/xpcshell/test_sync_profile_engine.js
+++ b/toolkit/components/search/tests/xpcshell/test_sync_profile_engine.js
@@ -1,25 +1,24 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-const NS_APP_USER_SEARCH_DIR  = "UsrSrchPlugns";
-
 function run_test() {
   removeMetadata();
   removeCacheFile();
 
   do_load_manifest("data/chrome.manifest");
 
   configureToLoadJarEngines();
 
-  // Copy an engine in [profile]/searchplugin/ and ensure it's not
+  // Copy an engine in [profile]/searchplugins/ and ensure it's not
   // overriding the same file from a jar.
   // The description in the file we are copying is 'profile'.
-  let dir = Services.dirsvc.get(NS_APP_USER_SEARCH_DIR, Ci.nsIFile);
+  let dir = gProfD.clone();
+  dir.append("searchplugins");
   if (!dir.exists())
     dir.create(dir.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
   do_get_file("data/engine-override.xml").copyTo(dir, "bug645970.xml");
 
   do_check_false(Services.search.isInitialized);
 
   // test engines from dir are not loaded.
   let engines = Services.search.getEngines();