Closed Bug 809920 Opened 8 years ago Closed 7 years ago

Provide test only module to define nsIXULAppInfo for tests


(Testing :: XPCShell Harness, defect)

Not set


(Not tracked)



(Reporter: gps, Assigned: gps)



(Keywords: dev-doc-complete)


(1 file)

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

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?
Flags: needinfo?(ted)
I'd vote for testing/modules.
Flags: needinfo?(ted)
Duplicate of this bug: 567554
Any reason why xpcshell doesn't have a valid nsIXULAppInfo registered at;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.
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.
Assignee: nobody → gps
Attachment #709186 - Flags: review?(ted)
Attachment #709186 - Flags: review?(ted) → review+
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla21
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
You need to log in before you can comment on or make changes to this bug.