Bug 1465457 - Part 1 - Add a function to register chrome URL overrides in test harnesses. draft
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Wed, 30 May 2018 15:42:48 +0100
changeset 801459 e350e7f0ed92c395f4218310042d33b9b134fa8a
parent 800874 f01bb6245db1ea2a87e5360104a4110571265137
child 801460 6b22b37c6adf8af89753f6341b4f358f38e9f428
push id111684
push userpaolo.mozmail@amadzone.org
push dateWed, 30 May 2018 14:43:46 +0000
bugs1465457
milestone62.0a1
Bug 1465457 - Part 1 - Add a function to register chrome URL overrides in test harnesses. MozReview-Commit-ID: IgLcidpoDfq
chrome/nsChromeRegistry.cpp
chrome/nsChromeRegistry.h
chrome/nsIChromeRegistry.idl
--- a/chrome/nsChromeRegistry.cpp
+++ b/chrome/nsChromeRegistry.cpp
@@ -304,16 +304,29 @@ nsChromeRegistry::ConvertChromeURL(nsIUR
     LogMessage("No chrome package registered for chrome://%s/%s/%s",
                package.get(), provider.get(), path.get());
     return NS_ERROR_FILE_NOT_FOUND;
   }
 
   return NS_NewURI(aResult, path, nullptr, baseURI);
 }
 
+NS_IMETHODIMP
+nsChromeRegistry::RegisterChromeURLOverrideForTest(nsIURI* aChromeURI,
+                                                   nsIURI* aOverrideURI)
+{
+  if (NS_WARN_IF(!aChromeURI) || NS_WARN_IF(!aOverrideURI)) {
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  mOverrideTable.Put(aChromeURI, aOverrideURI);
+
+  return NS_OK;
+}
+
 ////////////////////////////////////////////////////////////////////////
 
 // theme stuff
 
 
 static void FlushSkinBindingsForWindow(nsPIDOMWindowOuter* aWindow)
 {
   // Get the document.
--- a/chrome/nsChromeRegistry.h
+++ b/chrome/nsChromeRegistry.h
@@ -55,16 +55,18 @@ public:
   NS_IMETHOD CanLoadURLRemotely(nsIURI* url,
                                 bool* _retval) override;
   NS_IMETHOD MustLoadURLRemotely(nsIURI* url,
                                  bool* _retval) override;
 
   // nsIChromeRegistry methods:
   NS_IMETHOD_(bool) WrappersEnabled(nsIURI *aURI) override;
   NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURI, nsIURI* *aResult) override;
+  NS_IMETHOD RegisterChromeURLOverrideForTest(nsIURI* aChromeURI,
+                                              nsIURI* aOverrideURI) override;
 
   // nsChromeRegistry methods:
   nsChromeRegistry() : mInitialized(false) { }
 
   virtual nsresult Init();
 
   static already_AddRefed<nsIChromeRegistry> GetService();
 
--- a/chrome/nsIChromeRegistry.idl
+++ b/chrome/nsIChromeRegistry.idl
@@ -30,16 +30,31 @@ interface nsIChromeRegistry : nsISupport
    *   "css" for a "skin" package, and
    *   "dtd" for a "locale" package.
    *
    * @param aChromeURL the URL that is to be converted.
    */
   nsIURI convertChromeURL(in nsIURI aChromeURL);
 
   /**
+   * Registers an override. If convertChromeURL is then called with aChromeURL
+   * as the argument, aOverrideURL will be returned.
+   *
+   * This function should only be called in functional test harnesses, and not
+   * in production code, including non-test add-ons, because this may slow down
+   * the conversions, there is no way to unregister the overrides individually,
+   * and checkForNewChrome will clear the overrides added by this function.
+   *
+   * @param aChromeURL the URL that is to be converted.
+   * @param aOverrideURL the result of the conversion.
+   */
+  void registerChromeURLOverrideForTest(in nsIURI aChromeURL,
+                                        in nsIURI aOverrideURL);
+
+  /**
    * refresh the chrome list at runtime, looking for new packages/etc
    */
   void checkForNewChrome();
 
   /**
    * returns whether XPCNativeWrappers are enabled for aURI.
    */
   [notxpcom] boolean wrappersEnabled(in nsIURI aURI);