add a way to mock services in xpcshell tests

NEW
Unassigned

Status

()

Firefox
Developer Tools: Framework
P3
enhancement
3 years ago
6 months ago

People

(Reporter: tromey, Unassigned)

Tracking

(Blocks: 1 bug)

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

3 years ago
I tried to create a new subtype of DevToolsLoader that would allow mocking
services.  This way, more tests could be written as xpcshell tests rather than
mochitests.

See the attached patch.

This approach fails because, we think, the DevToolsLoader binds "require" to
its own "this", which happens too early.  This results on a call being made
on an object that doesn't have _mockedServices set, leading to this trace:

 0:00.09 LOG: Thread-1 ERROR TypeError: invalid 'in' operand this._mockedServices at /home/tromey/firefox-git/gecko-dev/obj-x86_64-unknown-linux-gnu/_tests/xpcshell/toolkit/devtools/tests/unit/head_devtools.js:33
DevToolsTestLoader.prototype.lazyServiceGetter@/home/tromey/firefox-git/gecko-dev/obj-x86_64-unknown-linux-gnu/_tests/xpcshell/toolkit/devtools/tests/unit/head_devtools.js:33:1
@resource://gre/modules/devtools/css-color.js:444:1
DevToolsLoader.prototype.require@resource://gre/modules/devtools/Loader.jsm:302:12
@/home/tromey/firefox-git/gecko-dev/obj-x86_64-unknown-linux-gnu/_tests/xpcshell/toolkit/devtools/tests/unit/test_cssColor.js:35:22
load_file@/home/tromey/firefox-git/gecko-dev/testing/xpcshell/head.js:600:7
_load_files@/home/tromey/firefox-git/gecko-dev/testing/xpcshell/head.js:612:3
_execute_test@/home/tromey/firefox-git/gecko-dev/testing/xpcshell/head.js:494:3


It would be nice if the loader supported this sort of mocking or subtyping.

Updated

6 months ago
Severity: normal → enhancement
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.