Share the HttpServer and pref setup of dom/geolocation/test/unit xpcshell tests via a head.js helper
Categories
(Core :: DOM: Geolocation, task)
Tracking
()
People
(Reporter: jstutte, Assigned: me, Mentored)
Details
(Keywords: good-first-bug, Whiteboard: [lang=js])
Attachments
(1 external file)
Filing as a good first bug to learn workflows.
Most xpcshell tests in dom/geolocation/test/unit repeat the same setup: call do_get_profile(), initialize FOG with Services.fog.initializeFOG(), start an HttpServer with a "/geo" path handler, and point the geo.provider.network.url pref at it while setting geo.provider.network.scan to false. The block is copy-pasted, with small variations, into test_geolocation_provider.js, test_geolocation_provider_timeout.js, test_geolocation_provider_shutdown.js, test_geolocation_monitor.js, test_geolocation_network_cache.js, test_geolocation_timeout.js, test_geolocation_timeout_wrap.js and test_geolocation_reset_accuracy.js.
Add a head.js in that directory with a helper, for example setupGeoServer(geoHandler), that performs this setup, registers a cleanup function stopping the server, and returns the HttpServer (or its port). Register the head file in xpcshell.toml via the head key, then convert each test to call the helper instead of its own copy. Keep per-test differences (extra prefs, different handlers) inside the test itself. Tests that run in a wrapped child process (the *_wrap.js tests) do their setup in the parent before run_test_in_child(); read them carefully before deciding whether the helper fits.
Link to the code (one copy of the block):
https://searchfox.org/firefox-main/rev/9779d0c588762208f33a82c9fc710f81466f6e9e/dom/geolocation/test/unit/test_geolocation_provider_timeout.js#39
To verify the fix:
./mach lint -l eslint dom/geolocation/test/unit
./mach xpcshell-test dom/geolocation/test/unit
This came out of the review of D325308 (bug 2071182), where the reviewer asked to stop copy-pasting the setup and add a helper instead. New head files are picked up by ./mach build faster if xpcshell reports a missing file.
Tutorial to contribute:
https://firefox-source-docs.mozilla.org/contributing/contribution_quickref.html
https://firefox-source-docs.mozilla.org/contributing/stack_quickref.html
Please don't ask for the bug to be assigned. It will be automatically assigned to the first patch.
| Assignee | ||
Comment 1•26 days ago
|
||
While working on this, I noticed that test_geolocation_timeout_wrap.js doesn't actually exercise the timeout path.
The wrapper starts an HttpServer in the parent but never registers a "/geo" handler. test_geolocation_timeout.js only sets up its own server and geoHandler when running in the parent process, so in the wrapped run the request hits the wrapper's server and gets an immediate 404:
- NetworkGeolocationProvider: "Sending IP-address-based geolocation request to network service: http://localhost:54510/geo"
- The geolocation provider returned a non-ok status 404
- PASS errorCallback
errorCallback fires about 40 ms after the request is sent, rather than after the 2000 ms timeout, so the test passes for the wrong reason. The non-wrapped run behaves as intended.
Converting the wrapper to the new helper would mean giving it a handler, which changes what the test does. Would you prefer that I fix it here or file a separate bug and keep this one a pure refactor?
| Assignee | ||
Comment 2•15 days ago
|
||
The setup was copy-pasted into each test and had started to drift between
copies; keeping per-test differences in the tests makes them stand out.
test_geolocation_timeout(_wrap).js keep their own setup for now, see
bug 2071920 comment 1.
Updated•15 days ago
|
Description
•