Add helper function to register extension APIs in tests
Categories
(WebExtensions :: General, task, P3)
Tracking
(Not tracked)
People
(Reporter: robwu, Unassigned)
References
Details
(Whiteboard: [addons-jira])
There are some tests that register a new extension API, which involves quite some setup:
- https://searchfox.org/mozilla-central/rev/a17011de808c24f015ad03debe7a157c1b43b602/toolkit/components/extensions/test/xpcshell/test_ext_schemas_manifest_permissions.js#6-73
- https://searchfox.org/mozilla-central/rev/a17011de808c24f015ad03debe7a157c1b43b602/toolkit/components/extensions/test/xpcshell/test_ext_schemas_privileged.js#9-46,95-99
- https://searchfox.org/mozilla-central/rev/a17011de808c24f015ad03debe7a157c1b43b602/toolkit/components/extensions/test/xpcshell/test_ext_persistent_events.js#5-113,170,174-182
- toolkit/mozapps/extensions/test/xpcshell/test_update_isPrivileged.js (https://phabricator.services.mozilla.com/D131682)
A typical way to register the ExtensionAPI is to generate a blob:
-URL and use that. But the parent process disallows blob:-URLs as scripts, unless security.allow_parent_unrestricted_js_loads
is set. It is possible to use a resource:-URL (see test_update_isPrivileged for an example, in D131682), so we could use that in a central method.
The first two tests and the last test use the category manager, whereas the latter invokes ExtensionParent.apiManager.registerModules(MODULE_INFO);
to register the module. We should try to unify the logic.
The first two tests don't set the security.allow_parent_unrestricted_js_loads
pref, but that seems to work because these tests don't actually invoke the test extension API. For better coverage these tests should also be calling the test extension APIs.
With the helper present, it may be easier to use it to register extension APIs, instead of using experiment_apis
for it. Here is an example of a test that marked an extension as privileged in order to use a special extension API as part of the test: https://searchfox.org/mozilla-central/rev/a17011de808c24f015ad03debe7a157c1b43b602/toolkit/components/extensions/test/xpcshell/test_ext_runtime_ports_gc.js#90 (if we register an extension API instead of an experimental API, we can remove isPrivileged
so that the test is a closer match to most real-world extensions).
Reporter | ||
Comment 1•3 years ago
|
||
Marking as depends on bug 1734987, because the following test is part of that bug: toolkit/mozapps/extensions/test/xpcshell/test_update_isPrivileged.js (https://phabricator.services.mozilla.com/D131682).
Resolving this bug is as simple as moving the above to a test helper, and fixing the other issues mentioned in the report.
Updated•3 years ago
|
Reporter | ||
Updated•3 years ago
|
Updated•3 years ago
|
Description
•