Bug 474043 - Part 4 - Cleanup some JSON suffixes. r=paolo draft
authorMarco Bonardo <mbonardo@mozilla.com>
Tue, 13 Mar 2018 17:50:17 +0100
changeset 767959 241e6ff07638c7556b024e9c0d3904deb5365da8
parent 767958 fde15e33a2ba047c62b99d744244e9596aa254f1
child 767960 93685ad059d32e66007e1dafb70df28a591ffa29
push id102760
push usermak77@bonardo.net
push dateThu, 15 Mar 2018 14:10:54 +0000
reviewerspaolo
bugs474043
milestone61.0a1
Bug 474043 - Part 4 - Cleanup some JSON suffixes. r=paolo MozReview-Commit-ID: cja118sBOO
uriloader/exthandler/tests/HandlerServiceTestUtils.jsm
uriloader/exthandler/tests/unit/head.js
uriloader/exthandler/tests/unit/test_handlerService_store.js
--- a/uriloader/exthandler/tests/HandlerServiceTestUtils.jsm
+++ b/uriloader/exthandler/tests/HandlerServiceTestUtils.jsm
@@ -17,36 +17,31 @@ ChromeUtils.import("resource://gre/modul
 ChromeUtils.import("resource://testing-common/Assert.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "gExternalProtocolService",
                                    "@mozilla.org/uriloader/external-protocol-service;1",
                                    "nsIExternalProtocolService");
 XPCOMUtils.defineLazyServiceGetter(this, "gMIMEService",
                                    "@mozilla.org/mime;1",
                                    "nsIMIMEService");
+XPCOMUtils.defineLazyServiceGetter(this, "gHandlerService",
+                                  "@mozilla.org/uriloader/handler-service;1",
+                                  "nsIHandlerService");
 
 var HandlerServiceTestUtils = {
   /**
-   * This has to be initialized to the nsIHandlerService instance under testing.
-   *
-   * When support for migration from the RDF to the JSON back-end is removed,
-   * this can be replaced by a lazy getter for the default implementation.
-   */
-  handlerService: null,
-
-  /**
    * Retrieves the names of all the MIME types and protocols configured in the
    * handler service instance currently under testing.
    *
    * @return Array of strings like "example/type" or "example-scheme", sorted
    *         alphabetically regardless of category.
    */
   getAllHandlerInfoTypes() {
     let handlerInfoTypes = [];
-    let handlerInfoEnumerator = this.handlerService.enumerate();
+    let handlerInfoEnumerator = gHandlerService.enumerate();
     while (handlerInfoEnumerator.hasMoreElements()) {
       let handlerInfo = handlerInfoEnumerator.getNext()
                                              .QueryInterface(Ci.nsIHandlerInfo);
       handlerInfoTypes.push(handlerInfo.type);
     }
     return handlerInfoTypes.sort();
   },
 
@@ -92,30 +87,30 @@ var HandlerServiceTestUtils = {
         while (handlerInfo.possibleApplicationHandlers.length > 1) {
           handlerInfo.possibleApplicationHandlers.removeElementAt(1);
         }
       } else {
         handlerInfo.possibleApplicationHandlers.clear();
       }
       handlerInfo.setFileExtensions("");
       // Populate the object from the handler service instance under testing.
-      if (this.handlerService.exists(handlerInfo)) {
-        this.handlerService.fillHandlerInfo(handlerInfo, "");
+      if (gHandlerService.exists(handlerInfo)) {
+        gHandlerService.fillHandlerInfo(handlerInfo, "");
       }
       return handlerInfo;
     }
 
     // Populate the protocol information from the handler service instance under
     // testing, like the nsIExternalProtocolService::GetProtocolHandlerInfo
     // method does on the default nsIHandlerService instance.
     let osDefaultHandlerFound = {};
     let handlerInfo = gExternalProtocolService.getProtocolHandlerInfoFromOS(
                                                   type, osDefaultHandlerFound);
-    if (this.handlerService.exists(handlerInfo)) {
-      this.handlerService.fillHandlerInfo(handlerInfo, "");
+    if (gHandlerService.exists(handlerInfo)) {
+      gHandlerService.fillHandlerInfo(handlerInfo, "");
     } else {
       gExternalProtocolService.setProtocolHandlerDefaults(
                                   handlerInfo, osDefaultHandlerFound.value);
     }
     return handlerInfo;
   },
 
   /**
--- a/uriloader/exthandler/tests/unit/head.js
+++ b/uriloader/exthandler/tests/unit/head.js
@@ -13,55 +13,55 @@ ChromeUtils.import("resource://gre/modul
 ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 ChromeUtils.import("resource://gre/modules/osfile.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 ChromeUtils.import("resource://testing-common/HandlerServiceTestUtils.jsm", this);
 ChromeUtils.import("resource://testing-common/TestUtils.jsm");
 
-XPCOMUtils.defineLazyServiceGetter(this, "gHandlerServiceJSON",
+XPCOMUtils.defineLazyServiceGetter(this, "gHandlerService",
                                    "@mozilla.org/uriloader/handler-service;1",
                                    "nsIHandlerService");
 
 do_get_profile();
 
 let jsonPath = OS.Path.join(OS.Constants.Path.profileDir, "handlers.json");
 
 /**
  * Unloads the nsIHandlerService data store, so the back-end file can be
  * accessed or modified, and the new data will be loaded at the next access.
  */
-let unloadHandlerStoreJSON = async function() {
+let unloadHandlerStore = async function() {
   // If this function is called before the nsIHandlerService instance has been
   // initialized for the first time, the observer below will not be registered.
   // We have to force initialization to prevent the function from stalling.
-  gHandlerServiceJSON;
+  gHandlerService;
 
   let promise = TestUtils.topicObserved("handlersvc-json-replace-complete");
   Services.obs.notifyObservers(null, "handlersvc-json-replace", null);
   await promise;
 };
 
 /**
  * Unloads the data store and deletes it.
  */
-let deleteHandlerStoreJSON = async function() {
-  await unloadHandlerStoreJSON();
+let deleteHandlerStore = async function() {
+  await unloadHandlerStore();
 
   await OS.File.remove(jsonPath, { ignoreAbsent: true });
 };
 
 /**
  * Unloads the data store and replaces it with the test data file.
  */
-let copyTestDataToHandlerStoreJSON = async function() {
-  await unloadHandlerStoreJSON();
+let copyTestDataToHandlerStore = async function() {
+  await unloadHandlerStore();
 
   await OS.File.copy(do_get_file("handlers.json").path, jsonPath);
 };
 
 /**
  * Ensures the files are removed and the services unloaded when the tests end.
  */
 registerCleanupFunction(async function test_terminate() {
-  await deleteHandlerStoreJSON();
+  await deleteHandlerStore();
 });
--- a/uriloader/exthandler/tests/unit/test_handlerService_store.js
+++ b/uriloader/exthandler/tests/unit/test_handlerService_store.js
@@ -1,22 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /*
- * Tests the nsIHandlerService interface using the JSON backend.
+ * Tests the nsIHandlerService interface.
  */
 
-let gHandlerService = gHandlerServiceJSON;
-let unloadHandlerStore = unloadHandlerStoreJSON;
-let deleteHandlerStore = deleteHandlerStoreJSON;
-let copyTestDataToHandlerStore = copyTestDataToHandlerStoreJSON;
-
-HandlerServiceTestUtils.handlerService = gHandlerService;
-
 // Set up an nsIWebHandlerApp instance that can be used in multiple tests.
 let webHandlerApp = Cc["@mozilla.org/uriloader/web-handler-app;1"]
                       .createInstance(Ci.nsIWebHandlerApp);
 webHandlerApp.name = "Web Handler";
 webHandlerApp.uriTemplate = "https://www.example.com/?url=%s";
 let expectedWebHandlerApp = {
   name: webHandlerApp.name,
   uriTemplate: webHandlerApp.uriTemplate,
@@ -438,17 +431,17 @@ add_task(async function test_store_no_du
       "extension_test1",
       "extension_test2",
     ],
   });
 });
 
 /**
  * Tests that "store" deletes properties that have their default values from
- * the data store. This is mainly relevant for the JSON back-end.
+ * the data store.
  *
  * File extensions are never deleted once they have been associated.
  */
 add_task(async function test_store_deletes_properties_except_extensions() {
   await deleteHandlerStore();
 
   // Prepare an nsIHandlerInfo instance with all the properties set to values
   // that will result in deletions. The preferredAction is also set to a defined
@@ -610,17 +603,17 @@ add_task(async function test_default_pro
   await assertAllHandlerInfosMatchDefaultHandlers();
 
   Services.prefs.setStringPref("gecko.handlerService.defaultHandlersVersion",
                                originalDefaultHandlersVersion);
 });
 
 /**
  * Ensures forward compatibility by checking that the "store" method preserves
- * unknown properties in the test data. This is specific to the JSON back-end.
+ * unknown properties in the test data.
  */
 add_task(async function test_store_keeps_unknown_properties() {
   // Create a new nsIHandlerInfo instance before loading the test data.
   await deleteHandlerStore();
   let handlerInfo =
       HandlerServiceTestUtils.getHandlerInfo("example/type.handleinternally");
 
   await copyTestDataToHandlerStore();