Note: There are a few cases of duplicates in user autocompletion which are being worked on.

Provide test only module to define nsIXULAppInfo for tests

RESOLVED FIXED in mozilla21

Status

Testing
XPCShell Harness
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: gps, Assigned: gps)

Tracking

({dev-doc-complete})

Trunk
mozilla21
dev-doc-complete
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Assignee)

Description

5 years ago
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.
(Assignee)

Comment 1

5 years ago
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?
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 @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.
Blocks: 837212
(Assignee)

Comment 5

5 years ago
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.
Assignee: nobody → gps
Status: NEW → ASSIGNED
Attachment #709186 - Flags: review?(ted)
Attachment #709186 - Flags: review?(ted) → review+
(Assignee)

Comment 6

5 years ago
https://hg.mozilla.org/integration/mozilla-inbound/rev/d7b65369292a
https://hg.mozilla.org/mozilla-central/rev/d7b65369292a
Status: ASSIGNED → RESOLVED
Last Resolved: 5 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
Cu.import("resource://testing-common/AppInfo.jsm");
updateAppInfo();
I updated MDN accordingly:

https://developer.mozilla.org/en-US/docs/Using_nsIXULAppInfo#Getting_nsIXULAppInfo
Keywords: dev-doc-complete
Blocks: 839670
You need to log in before you can comment on or make changes to this bug.