Files
Andrew McCreight 83b163b91b Bug 2065291 - Never createInstance in MockRegistrar. r=extension-reviewers,kpatenio,chutten,robwu,hiro
The shouldCreateInstance option for MockRegistrar, which is true by default,
makes it so that every time you call createInstance on the mock component it
calls createInstance on the real component, and sticks the real instance on
a property _genuine. This can be used for things like forwarding calls you
don't want to change to the real component.

Unfortunately, in order to support the full generality of MockRegistrar, this
is implemented in terms of a low-level XPCOM component manager feature called
getClassObject, which gets a handle to the underlying factory. I am trying to
get rid of it.

However, this feature is only used in two specific places, in FakeCertDB and
in telemetry. Both of them only forward a few property lookups to the real
component, and the actual real component doesn't seem to change, so we can
manually snapshot it when we create the mock component and then remove this
feature from MockRegistrar entirely.

Removing this option means that there are no options, so I merged registerEx
into register.

Another non-obvious thing is that there's a try-catch around the starting part
of the function where we check for an existing component. I found at least one
test, browser_downloads_taskbar.js, that relies on this. It registers a mock
component for some OS-specific things, across every OS, so we need to be able to
handle this gracefully. Now that this can only fail in one place, I tightened
up the try-catch.

Differential Revision: https://phabricator.services.mozilla.com/D320276
2026-09-11 04:18:05 +00:00
..