A common pattern in xpcshell and other test suites is to define nsIXULAppInfo with "dummy" fields to facilitate testing of certain features. There are even cases where the values need to agree across different sets of tests for tests to pass (e.g. the tests for Sync and AddonManager need the same application name otherwise the add-on sync functionality won't work).
I think it would be handy for the common "define nsIXULAppInfo for this test suite" boilerplate code to live in a common test only JS module. If you need app info, you can import this module and call a function. If not or if you don't want the shared/common defaults, you don't.
One can make the argument that all tests may want to share a common nsIXULAppInfo. We could certainly explore that. Although we may have to provide a backdoor via xpcshell.ini, etc to disable this.
I'm filing this bug in xpcshell runner because this problems seems to bite xpcshell tests more than other tests suites since they don't run in the context of a larger XUL application.
I accidentally landed something in https://hg.mozilla.org/services/services-central/rev/4ac2babbafec.
I'd love it if we had a central directory containing generic test-only JSMs like this.
Ted: What's a good place in the tree for generic test-only JSMs? testing/jsms?
I'd vote for testing/modules.
*** Bug 567554 has been marked as a duplicate of this bug. ***
Any reason why xpcshell doesn't have a valid nsIXULAppInfo registered at @mozilla.org/xre/app-info;1? Some tests might still want to override it, but xpcshell tests of other modules that happen to refer to Services.appinfo fail with the following exception, because the lazy getter in Services.jsm assumes that xre/app-info implements the nsIXULAppInfo interface.
TEST-UNEXPECTED-FAIL | /Users/ireid/tbird/obj/mozilla-central/_tests/xpcshell/toolkit/modules/tests/xpcshell/test_TelemetryTimestamps.js | Failed: [Exception... "Component returned failure code: 0x80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE) [nsIJSCID.getService]" nsresult: "0x80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE)" location: "JS frame :: resource://gre/modules/Services.jsm :: <TOP_LEVEL> :: line 22" data: no] ...
I tripped over this while trying to test TelemetryTimestamps.jsm, which depends on TelemetryPing.jsm, which uses Services.appinfo. Having these buried dependencies fail under the test harness reduces the level of fun being had.
Created attachment 709186 [details] [diff] [review]
Create testing/modules and copy XULAppInfo modifier there, v1
I pretty much copied the JSM from /services/healthreport and didn't modify the original file out of concerns that a lot of FHR code is being uplifted and I want to reduce potential for merge conflicts.
I manually ran a build and verified AppInfo.jsm is installed in the proper location alongside existing testing-only JSMs.
For those who come after, the incantation to use this module in your xpcshell test is:
// Work around the fact that XPCSHELL doesn't have a proper app-info XPCOM object
I updated MDN accordingly: