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)
Testing
General
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: Paolo, Assigned: darktrojan)
References
Details
Attachments
(1 file, 1 obsolete file)
4.67 KB,
patch
|
Details | Diff | Splinter Review |
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
Reporter | ||
Comment 1•16 years ago
|
||
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?
Assignee | ||
Comment 2•15 years ago
|
||
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 3•15 years ago
|
||
Comment on attachment 460003 [details] [diff] [review]
patch
r=sdwilsh
Attachment #460003 -
Flags: review?(sdwilsh) → review+
Updated•15 years ago
|
Assignee: nobody → geoff
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Reporter | ||
Comment 4•15 years ago
|
||
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).
Assignee | ||
Comment 6•15 years ago
|
||
Location of file and copy swapped as requested.
Attachment #460003 -
Attachment is obsolete: true
Assignee | ||
Updated•15 years ago
|
Keywords: checkin-needed
Comment 7•14 years ago
|
||
(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])?
Reporter | ||
Comment 8•14 years ago
|
||
(In reply to comment #7)
> Did you mean "hg rename" (as in attachment 462357 [details] [diff] [review])?
Of course.
Comment 9•14 years ago
|
||
I tried landing this, but the patch no longer applies cleanly.
Keywords: checkin-needed
Assignee | ||
Comment 10•14 years ago
|
||
(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.
You need to log in
before you can comment on or make changes to this bug.
Description
•