Auto-install extensions unit tests

This is a squashed version of PR #9581

Auto-install extensions unit tests, bug fixes, code cleanup

This adds unit tests for auto-installing extensions
* refactored code to facilitate testing
* added jsdoc annotations
* minor code cleanup
* fixes #9576

cc @dangoor 

I just did some testing and one thing I hadn't considered with this plan is that it now logs an error every time except for the first time when it successfully installs the extension. This should log nothing if `errorObj.error` is undefined (or falsy would be fine, too).