Bug 1254694 - Fix synchronous code path for search engines metadata migration. r=adw, a=sledru
authorFlorian Quèze <florian@queze.net>
Thu, 10 Mar 2016 21:04:54 +0100
changeset 323416 5b899aff5f55966355016f121482de1d87b95269
parent 323415 4dac2eacb3d01215b82c5ba395cbb5575fe744fd
child 323417 83559d0c94aa7f81dea9a6bf26cf706c2f30bf72
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw, sledru
bugs1254694
milestone47.0a2
Bug 1254694 - Fix synchronous code path for search engines metadata migration. r=adw, a=sledru
toolkit/components/search/nsSearchService.js
toolkit/components/search/tests/xpcshell/test_async_migration.js
toolkit/components/search/tests/xpcshell/test_migration.js
toolkit/components/search/tests/xpcshell/test_sync_migration.js
toolkit/components/search/tests/xpcshell/xpcshell.ini
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -3177,18 +3177,18 @@ SearchService.prototype = {
       stream.close();
     }
 
     try {
       cacheFile.leafName = "search-metadata.json";
       stream = Cc["@mozilla.org/network/file-input-stream;1"].
                  createInstance(Ci.nsIFileInputStream);
       stream.init(cacheFile, MODE_RDONLY, FileUtils.PERMS_FILE, 0);
-      let metadata = json.decodeFromStream(stream, stream.available());
-      let json;
+      let metadata = parseJsonFromStream(stream);
+      let json = {};
       if ("[global]" in metadata) {
         LOG("_readCacheFile: migrating metadata from search-metadata.json");
         let data = metadata["[global]"];
         json.metaData = {};
         let fields = ["searchDefault", "searchDefaultHash", "searchDefaultExpir",
                       "current", "hash",
                       "visibleDefaultEngines", "visibleDefaultEnginesHash"];
         for (let field of fields) {
@@ -3197,17 +3197,17 @@ SearchService.prototype = {
             json.metaData[field] = data[name];
         }
       }
       delete metadata["[global]"];
       json._oldMetadata = metadata;
 
       return json;
     } catch(ex) {
-      LOG("_readCacheFile: failed to read old metadata");
+      LOG("_readCacheFile: failed to read old metadata: " + ex);
       return {};
     } finally {
       stream.close();
     }
   },
 
   /**
    * Read the cache file asynchronously. This also imports data from the old
rename from toolkit/components/search/tests/xpcshell/test_migration.js
rename to toolkit/components/search/tests/xpcshell/test_async_migration.js
--- a/toolkit/components/search/tests/xpcshell/test_migration.js
+++ b/toolkit/components/search/tests/xpcshell/test_async_migration.js
@@ -8,21 +8,18 @@ function run_test() {
   updateAppInfo();
   installTestEngine();
 
   do_get_file("data/metadata.json").copyTo(gProfD, "search-metadata.json");
 
   run_next_test();
 }
 
-add_task(function* test_metadata_migration() {
-
-  yield new Promise(function(resolve) {
-    Services.search.init(resolve);
-  });
+add_task(function* test_async_metadata_migration() {
+  yield asyncInit();
   yield promiseAfterCache();
 
   // Check that the entries are placed as specified correctly
   let metadata = yield promiseEngineMetadata();
   do_check_eq(metadata["engine"].order, 1);
   do_check_eq(metadata["engine"].alias, "foo");
 
   metadata = yield promiseGlobalMetadata();
copy from toolkit/components/search/tests/xpcshell/test_migration.js
copy to toolkit/components/search/tests/xpcshell/test_sync_migration.js
--- a/toolkit/components/search/tests/xpcshell/test_migration.js
+++ b/toolkit/components/search/tests/xpcshell/test_sync_migration.js
@@ -8,21 +8,20 @@ function run_test() {
   updateAppInfo();
   installTestEngine();
 
   do_get_file("data/metadata.json").copyTo(gProfD, "search-metadata.json");
 
   run_next_test();
 }
 
-add_task(function* test_metadata_migration() {
-
-  yield new Promise(function(resolve) {
-    Services.search.init(resolve);
-  });
+add_task(function* test_sync_metadata_migration() {
+  do_check_false(Services.search.isInitialized);
+  let engines = Services.search.getEngines();
+  do_check_true(Services.search.isInitialized);
   yield promiseAfterCache();
 
   // Check that the entries are placed as specified correctly
   let metadata = yield promiseEngineMetadata();
   do_check_eq(metadata["engine"].order, 1);
   do_check_eq(metadata["engine"].alias, "foo");
 
   metadata = yield promiseGlobalMetadata();
--- a/toolkit/components/search/tests/xpcshell/xpcshell.ini
+++ b/toolkit/components/search/tests/xpcshell/xpcshell.ini
@@ -63,25 +63,26 @@ support-files =
 [test_resultDomain.js]
 [test_searchSuggest.js]
 [test_async.js]
 [test_async_addon.js]
 tags = addons
 [test_async_addon_no_override.js]
 tags = addons
 [test_async_distribution.js]
+[test_async_migration.js]
 [test_async_profile_engine.js]
 [test_sync.js]
 [test_sync_addon.js]
 tags = addons
 [test_sync_addon_no_override.js]
 tags = addons
 [test_sync_distribution.js]
 [test_sync_fallback.js]
 [test_sync_delay_fallback.js]
+[test_sync_migration.js]
 [test_sync_profile_engine.js]
 [test_rel_searchform.js]
 [test_remove_profile_engine.js]
 [test_selectedEngine.js]
 [test_geodefaults.js]
 [test_hidden.js]
 [test_currentEngine_fallback.js]
-[test_migration.js]