As a security precaution, we have turned on the setting "Require API key authentication for API requests" for everyone. If this has broken something, please contact
Last Comment Bug 809920 - Provide test only module to define nsIXULAppInfo for tests
: Provide test only module to define nsIXULAppInfo for tests
: dev-doc-complete
Product: Testing
Classification: Components
Component: XPCShell Harness (show other bugs)
: Trunk
: All All
: -- normal (vote)
: mozilla21
Assigned To: Gregory Szorc [:gps]
: 567554 (view as bug list)
Depends on:
Blocks: 837212 839670
  Show dependency treegraph
Reported: 2012-11-08 09:37 PST by Gregory Szorc [:gps]
Modified: 2013-02-08 14:45 PST (History)
5 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---

Create testing/modules and copy XULAppInfo modifier there, v1 (7.32 KB, patch)
2013-02-01 11:59 PST, Gregory Szorc [:gps]
ted: review+
Details | Diff | Splinter Review

Description User image Gregory Szorc [:gps] 2012-11-08 09:37:52 PST
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.
Comment 1 User image Gregory Szorc [:gps] 2013-01-06 00:25:16 PST
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?
Comment 2 User image Ted Mielczarek [:ted.mielczarek] 2013-01-07 05:16:48 PST
I'd vote for testing/modules.
Comment 3 User image :Irving Reid (No longer working on Firefox) 2013-02-01 10:45:44 PST
*** Bug 567554 has been marked as a duplicate of this bug. ***
Comment 4 User image :Irving Reid (No longer working on Firefox) 2013-02-01 11:00:35 PST
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.
Comment 5 User image Gregory Szorc [:gps] 2013-02-01 11:59:53 PST
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.
Comment 7 User image Phil Ringnalda (:philor) 2013-02-03 12:46:48 PST
Comment 8 User image :Irving Reid (No longer working on Firefox) 2013-02-05 08:12:22 PST
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
Comment 9 User image Richard Newman [:rnewman] 2013-02-05 10:24:30 PST
I updated MDN accordingly:

Note You need to log in before you can comment on or make changes to this bug.