Bug 1465457 - Part 1 - Add a function to register chrome URL overrides in test harnesses.
MozReview-Commit-ID: IgLcidpoDfq
--- 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);