Bug 1639942 - Correctly register `Extension-Storage` engine alternatives. r=tcsc
authorLina Cambridge <lina@yakshaving.ninja>
Thu, 21 May 2020 18:55:37 +0000
changeset 531491 f350b8dff15db04d352d92aa8f46465aae5057ec
parent 531490 67745f2dd84827d30f654d75766351ff788f5114
child 531492 9c5b9c33920bd312f86167e9577a028e980a4678
push id37440
push userabutkovits@mozilla.com
push dateFri, 22 May 2020 09:43:16 +0000
treeherdermozilla-central@fbf71e4d2e21 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcsc
bugs1639942
milestone78.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 1639942 - Correctly register `Extension-Storage` engine alternatives. r=tcsc Alternative engines are registered using the lowercased version of the keys in the modules object. But `extension-storage` is hyphenated, so we need to use `Extension-Storage` (not `ExtensionStorage`) as the key name, to match the name of the engine and its collection. Without the hyphen, we'll register the alternative as `extensionstorage`, so it'll never be used because everything else expects the engine to be called `extension-storage`. Differential Revision: https://phabricator.services.mozilla.com/D76355
services/sync/modules/service.js
services/sync/tests/unit/test_extension_storage_engine.js
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -102,17 +102,17 @@ function getEngineModules() {
     };
   }
   result.Bookmarks = {
     module: "bookmarks.js",
     controllingPref: "services.sync.engine.bookmarks.buffer",
     whenFalse: "BookmarksEngine",
     whenTrue: "BufferedBookmarksEngine",
   };
-  result.ExtensionStorage = {
+  result["Extension-Storage"] = {
     module: "extension-storage.js",
     controllingPref: "webextensions.storage.sync.kinto",
     whenTrue: "ExtensionStorageEngineKinto",
     whenFalse: "ExtensionStorageEngineBridge",
   };
   return result;
 }
 
--- a/services/sync/tests/unit/test_extension_storage_engine.js
+++ b/services/sync/tests/unit/test_extension_storage_engine.js
@@ -1,24 +1,61 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   BridgedRecord: "resource://services-sync/bridged_engine.js",
   extensionStorageSync: "resource://gre/modules/ExtensionStorageSync.jsm",
-  ExtensionStorageEngineBridge:
-    "resource://services-sync/engines/extension-storage.js",
   Service: "resource://services-sync/service.js",
 });
 
-Services.prefs.setBoolPref("webextensions.storage.sync.kinto", false); // shouldn't need this
+const {
+  ExtensionStorageEngineBridge,
+  ExtensionStorageEngineKinto,
+} = ChromeUtils.import("resource://services-sync/engines/extension-storage.js");
+
 Services.prefs.setStringPref("webextensions.storage.sync.log.level", "debug");
 
+add_task(async function test_switching_between_kinto_and_bridged() {
+  function assertUsingKinto(message) {
+    let kintoEngine = Service.engineManager.get("extension-storage");
+    Assert.ok(kintoEngine instanceof ExtensionStorageEngineKinto, message);
+  }
+  function assertUsingBridged(message) {
+    let bridgedEngine = Service.engineManager.get("extension-storage");
+    Assert.ok(bridgedEngine instanceof ExtensionStorageEngineBridge, message);
+  }
+
+  let isUsingKinto = Services.prefs.getBoolPref(
+    "webextensions.storage.sync.kinto",
+    false
+  );
+  if (isUsingKinto) {
+    assertUsingKinto("Should use Kinto engine before flipping pref");
+  } else {
+    assertUsingBridged("Should use bridged engine before flipping pref");
+  }
+
+  _("Flip pref");
+  Services.prefs.setBoolPref("webextensions.storage.sync.kinto", !isUsingKinto);
+  await Service.engineManager.switchAlternatives();
+
+  if (isUsingKinto) {
+    assertUsingBridged("Should use bridged engine after flipping pref");
+  } else {
+    assertUsingKinto("Should use Kinto engine after flipping pref");
+  }
+
+  _("Clean up");
+  Services.prefs.clearUserPref("webextensions.storage.sync.kinto");
+  await Service.engineManager.switchAlternatives();
+});
+
 // It's difficult to know what to test - there's already tests for the bridged
 // engine etc - so we just try and check that this engine conforms to the
 // mozIBridgedSyncEngine interface guarantees.
 add_task(async function test_engine() {
   let engine = new ExtensionStorageEngineBridge(Service);
   Assert.equal(engine.version, 1);
 
   Assert.deepEqual(await engine.getSyncID(), null);