Closed Bug 485205 Opened 16 years ago Closed 14 years ago

Provide a helper for registering XPCOM mock object factories, usable from JavaScript tests

Categories

(Testing :: General, defect)

defect
Not set
minor

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: Paolo, Assigned: darktrojan)

References

Details

Attachments

(1 file, 1 obsolete file)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7 (.NET CLR 3.5.30729) Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2a1pre) Gecko/20090321 Minefield/3.6a1pre When an automated test needs to temporarily replace a standard XPCOM component with a mock implementation, four steps are required: * Preserve the original factory * Register the mock factory * Unregister the mock factory * Restore the original factory See this implemented in http://mxr.mozilla.org/mozilla-central/source/toolkit/content/tests/browser/browser_bug471962.js#104 Currently, there is at least one test that doesn't restore the original factory: http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/downloads/tests/chrome/test_bug_412360.xul It would be useful to have a shared component to handle these steps, usable from all the JavaScript-based testing frameworks. The object would register the factory on construction, then unregister it when its dispose() method is explicitly called. For example: var mockObject = { QueryInterface: function() { ... } ... } var registerer = new MockObjectRegisterer(mockObject, contractID, ...); try { ...call the functions that need the mock object... } finally { registerer.dispose(); } Comments? Reproducible: Always
Blocks: 484579
If someone suggests a place where this shared code could be located, I may try and write an actual patch. Maybe it could be written as a JavaScript module?
Attached patch patch (obsolete) — Splinter Review
This patch copies toolkit/content/tests/browser/common/mockObjects.js into mochitest's SimpleTest directory so it's available via HTTP as well as chrome://mochitest. Fixes a test for Android.
Attachment #460003 - Flags: review?(sdwilsh)
Comment on attachment 460003 [details] [diff] [review] patch r=sdwilsh
Attachment #460003 - Flags: review?(sdwilsh) → review+
Assignee: nobody → geoff
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
As implemented, this change introduces a dependency between the global testing framework and the Toolkit tests. In other words, I'm afraid that people might modify the mockObjects.js file without realizing that it is used by other tests outside of the Toolkit directory. I suggest to do the other way around: just "hg copy" the file to mochitest, and then reference it in Toolkit (either in Makefile or by loading it directly from HTTP).
That's likely a better idea. r=me with the change suggested in comment 4.
Attached patch patch v2Splinter Review
Location of file and copy swapped as requested.
Attachment #460003 - Attachment is obsolete: true
Keywords: checkin-needed
(In reply to comment #4) > I suggest to do the other way around: > just "hg copy" the file to mochitest. Did you mean "hg rename" (as in attachment 462357 [details] [diff] [review])?
(In reply to comment #7) > Did you mean "hg rename" (as in attachment 462357 [details] [diff] [review])? Of course.
I tried landing this, but the patch no longer applies cleanly.
Keywords: checkin-needed
(In reply to comment #9) > I tried landing this, but the patch no longer applies cleanly. I'm closing this bug as it's already been fixed in bug 591325.
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Depends on: 591325
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: