make Cu.isInAutomation set for xpcshell tests
Categories
(WebExtensions :: General, task, P3)
Tracking
(Not tracked)
People
(Reporter: mixedpuppy, Unassigned)
References
(Blocks 1 open bug)
Details
Attachments
(1 obsolete file)
We would like the flag set, at least for extension tests. Then we can remove an environment check done in D53981.
Reporter | ||
Updated•5 years ago
|
Comment 1•5 years ago
|
||
The goal here is to keep a useful browser.test
API without exposing dangerous functionality to extensions.
Updated•5 years ago
|
Comment 2•4 years ago
|
||
I looked into this, and it seems that the cleanest way to do this is to add a constant that is only set at compile time in the xcpshell binary. If needed, we can decouple "is xpcshell" and "is xpcshell test" by adding an additional check for an environment variable. Possibly around https://searchfox.org/mozilla-central/rev/bc3600def806859c31b2c7ac06e3d69271052a89/js/xpconnect/src/XPCShellImpl.cpp#1204
I'm suggesting something hard-coded at compile time, because toggles in prefs, environment variables and command-line arguments can inadvertently or maliciously be set. The flag "automation mode" should never be true in normal browser usage.
Comment 3•3 years ago
|
||
(In reply to Rob Wu [:robwu] from comment #2)
I looked into this, and it seems that the cleanest way to do this is to add a constant that is only set at compile time in the xcpshell binary. If needed, we can decouple "is xpcshell" and "is xpcshell test" by adding an additional check for an environment variable. Possibly around https://searchfox.org/mozilla-central/rev/bc3600def806859c31b2c7ac06e3d69271052a89/js/xpconnect/src/XPCShellImpl.cpp#1204
I'm suggesting something hard-coded at compile time, because toggles in prefs, environment variables and command-line arguments can inadvertently or maliciously be set. The flag "automation mode" should never be true in normal browser usage.
There's already an environment variable, MOZ_DISABLE_NONLOCAL_CONNECTIONS, which causes us to crash if we try to talk to anything but localhost. There aren't really useful ways of having that set and doing "normal browser usage". The gap with e.g. mochitests is that xpcshell doesn't set the let_viruses_take_over_this_computer pref. See also bug 1548941 comment 11. Changing that pref is a lot simpler than writing xpcshell-specific compiled code. You might even be able to set the pref in the xpcshell manifest for specific tests.
Either way there's likely to be fallout from code behind isInAutomation
checks that doesn't expect to run in xpcshell right now.
Comment 4•3 years ago
|
||
Oh, and indeed some webextension tests do exactly that, cf. https://searchfox.org/mozilla-central/rev/7b1de5e29d878cc163dec7beaf9b57a2f0f41aaa/toolkit/mozapps/extensions/test/xpcshell/test_seen.js#5-9
Comment 5•3 years ago
•
|
||
I would also be interested in that. Currently, we detect being in XPCShell tests using Cu.isInAutomation || env.exists("XPCSHELL_TEST_PROFILE_DIR")
in our code.
Comment 6•3 years ago
|
||
Out of interest, I took a quick poke at this and pushed a patch to try: https://treeherder.mozilla.org/jobs?repo=try&revision=b230069d5330f5b903e51db1cb1718e7e9180ae2
Most of the desktop failures there are attempted loads of SessionStore.jsm or AttributionCode.jsm (and other modules) in non browser/
locations code. I think there's also things like static pref changes in various android tests and possibly some gfx items as well.
Tackling the loads issue will likely fix most of it. Fixing the loads issue might be beneficial to help prevent us accessing things we shouldn't be. Unfortunately I'm not quite sure how exactly we should handle it. I could see various ways of providing SessionStore/AttributionCode stubs, or maybe even having a special ChromeUtils.defineModuleGetter that allows for the file not existing.
Updated•2 years ago
|
Updated•2 years ago
|
Comment 7•2 years ago
|
||
Comment 8•2 years ago
|
||
Note: the patch I just attached is the one I tried in comment 6. Just adding it here for easy reference, I'm not planning on working on this.
Updated•8 months ago
|
Description
•