Marionette test files for chrome scope should not be shipped with Firefox
Categories
(Testing :: Marionette Client and Harness, defect, P2)
Tracking
(firefox142 fixed)
Tracking | Status | |
---|---|---|
firefox142 | --- | fixed |
People
(Reporter: florian, Assigned: whimboo)
References
(Blocks 1 open bug)
Details
(Whiteboard: [webdriver:m17])
Attachments
(2 files)
Comment 1•8 years ago
|
||
Updated•8 years ago
|
Reporter | ||
Comment 2•8 years ago
|
||
Comment 3•8 years ago
|
||
Assignee | ||
Comment 4•8 years ago
|
||
Reporter | ||
Comment 5•8 years ago
|
||
Comment 6•8 years ago
|
||
Assignee | ||
Comment 7•8 years ago
|
||
Reporter | ||
Comment 8•8 years ago
|
||
Assignee | ||
Comment 9•8 years ago
|
||
Reporter | ||
Comment 10•8 years ago
|
||
Updated•8 years ago
|
Assignee | ||
Updated•4 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Assignee | ||
Updated•3 years ago
|
Assignee | ||
Comment 11•4 months ago
|
||
This bug came up again when talking to Simon Friedberger because those pages show CSP issues when evaluating JavaScript via Marionette in chrome scope. So whether we get the CSP issues fixed or as stated above remove those files from the official Firefox build.
I have taken a look at Mochitest and how it does the registration for the addon. As it looks like there is still a way to register chrome URLs dynamically even it was stated the feature is gone. But it needs to be done through an experimental API as it looks like:
This feature will probably stay given that it is required by Mochitests to work. But what I'm not sure about is if this would also require the preference extensions.experiments.enabled
to be set to true
. If that's true we may have to extract chrome scope tests into their own sub folder and maybe have to run a separate unit test job where we can then install the addon with the affected xhtml files registered correctly. Defining the preference should be done in the defaults section of the toml file so bug 1959688 would have to be fixed first.
Assignee | ||
Comment 12•4 months ago
|
||
Lets see if we can work on this bug for M16. Also because we would need such test cases as well for our WebDriver BiDi implementation.
Assignee | ||
Updated•3 months ago
|
Assignee | ||
Comment 13•3 months ago
•
|
||
I’ve extracted the relevant files and bundled them into an add-on that registers them for access via chrome URIs. However, this approach only works with unbranded builds of Firefox, but not with Beta or Release versions.
Registering a chrome handler requires meeting certain prerequisites:
extensions.experiments.enabled
must be set totrue
to use the registration API.- In Beta/Release builds, the
Cu.isInAutomation
flag also needs to betrue
, which is a flag that is never true when running tests via Marionette.
Since we can’t satisfy the second condition, we’ll need to create a privileged add-on similar to quitter. This kind of add-on can be signed and checked into the tree as an XPI, just like tools/quitter/.
Proposed Workflow for Updating the Extension:
- When test files need updating, use the upstream repository. You can generate an unsigned XPI locally using the
webext
tool to test the changes right away. - Request signing for the updated add-on. This process is mostly automated, though some steps may require manual intervention.
- Once signed, stash the updated XPI in
mozilla-central
under/remote/test/extensions/chrome-assets/
. - Submit a new Phabricator review to land the changes.
With the add-on-based approach in place, we’ll also need to implement the following:
-
Add a helper method to the Marionette test framework (either the test case or harness) that installs the add-on into the active profile when tests require access to
chrome://
URIs. This add-on should be automatically removed during test teardown. Note that the installation path may differ depending on whether the test is run viamach
ormozharness
; see this logic in mochitests for reference. -
Update all relevant tests to call this helper method when they rely on the
chrome://
resources exposed by the add-on. -
Update
test_archive.py
to include the add-on in the common test package. The final location within the archive should be chosen to allow sharing between Marionette and WDSpec tests.
Assignee | ||
Comment 14•3 months ago
|
||
Assignee | ||
Comment 15•3 months ago
•
|
||
Another option for tests that use those chrome pages would be to run them isolated in a specific test job with the disable_all_security
preference set to true - this is not a preference that we want to set in general for WebDriver and is required to be set before Firefox starts!
But when setting the preference, it would allow us to as well get the extension installed in a branded build because the check for Cu.isInAutomation
will then return true
.
However, this approach would bypass certain security checks, which risks masking failures or regressions that real Firefox users might encounter when automating with WebDriver. That said, I'm not necessarily opposed to taking that route.
Assignee | ||
Comment 16•3 months ago
•
|
||
There is actually another way to even simply it more. We discussed that yesterday in the Add-ons meeting and it indeed removes a lot of overhead and I think that this approach would work for us.
Instead of explicitly providing an add-on for those chrome files we could directly call the chrome registration handler when executing code in the chrome context. An example Marionette tests demonstrates it:
def test_chrome_window(self):
with self.marionette.using_context("chrome"):
self.marionette.execute_script("""
const { FileUtils } = ChromeUtils.importESModule(
"resource://gre/modules/FileUtils.sys.mjs"
);
XPCOMUtils.defineLazyServiceGetter(
this,
"aomStartup",
"@mozilla.org/addons/addon-manager-startup;1",
"amIAddonManagerStartup"
);
const registry = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(
Ci.nsIChromeRegistry
);
const path = "/Users/henrik/code/gecko/remote/test/chrome-assets/";
const rootURI = Services.io.newFileURI(new FileUtils.File(path));
const manifestURI = Services.io.newURI(
"manifest.json",
null,
rootURI
);
this.chromeHandle = aomStartup.registerChrome(
manifestURI,
[["content", "remote-chrome", "content/"]]
);
""")
new_window = self.open_chrome_window(
"chrome://remote-chrome/content/test.xhtml"
)
This works perfectly well in beta and release builds because there is no longer the need for the Experiments API and also the restriction for Cu.isInAutomation
is cleared.
I'll check if we can reduce the number of XHTML files so we maybe only need 3 of them for our tests. Given that we will have to share them with upcoming wdspec tests, it's not clear yet where we want to package them. As well we need a solution for the reftest.xhtml
and reftest-content.js
files which are needed by reftests under /layout
as well.
Assignee | ||
Comment 17•2 months ago
|
||
Moving out the chrome files for reftests is a bit more complicated given that it spans across Marionette unit tests and web-platform-tests. Especially that the latter will have to work upstream as well it's not that clear to me yet where to put the relevant xhtml and js files. As such I'll file a new bug to handle the reftest files after we have a fix landed here.
Updated•2 months ago
|
Updated•1 month ago
|
Assignee | ||
Comment 18•1 month ago
|
||
With the patch applied the CSP is failing and causing a crash because of inline styles and embedded iframes. While I could outsource the styles to a separate stylesheet, I'm not able to work around the iframe issue. Our test files need to check that.
Simon, what needs to be done to prevent the crash from happening? It looks like that <?csp default-src 'none'; ?>
is the only thing that I can add. Any other addition causes a crash as well. May we have to set security.csp.testing.allow_internal_csp_violation
to true
for those specific tests? I hope that we can circumvent that.
Comment 19•1 month ago
|
||
What exactly is the file you're having trouble with?
If you want to allow something you may need to add an exception in one of the lists here-ish: https://searchfox.org/mozilla-central/source/dom/security/nsContentSecurityUtils.cpp#1316
Assignee | ||
Comment 20•1 month ago
|
||
The most obvious thing are the inline styles that are used and which I was able to solve by moving it out into a separate stylesheet. But what's not working is that I can allow frames to be used. Those are always denied:
[70674] Hit MOZ_CRASH(Document (chrome://marionette-chrome/content/test.xhtml) must not contain a CSP with the unchecked directive frame-src) at /builds/worker/checkouts/gecko/dom/security/nsContentSecurityUtils.cpp:1968
#01: nsContentSecurityUtils::AssertChromePageHasCSP(mozilla::dom::Document*)[/Users/henrik/code/gecko-obj/debug/dist/NightlyDebug.app/Contents/MacOS/XUL +0x5065a80]
Also for the test_dialog.xhtml file I get:
Mozilla crash reason: Unexpected CSP violation on page chrome://marionette-chrome/content/test_dialog.xhtml caused by script-src-attr (URL: inline, Source: ) violating the directive: "default-src 'none'" (file: chrome://marionette-chrome/content/test_dialog.xhtml line: 0).
But none of the test files have actually an inline script defined. So not sure where this is actually coming from.
Assignee | ||
Comment 21•1 month ago
|
||
Discussed with Simon on Slack and we can actually use <?csp default-src chrome:; ?>
for those files that embed iframes. The other script related issue came from the inline oncommand=""
attribute for the button element in test_dialog.xhtml`. Removing it fixed it. I'll update the patch.
Comment 22•1 month ago
|
||
Comment 23•1 month ago
|
||
Comment 24•1 month ago
|
||
Backed out for causing multiple perma failures
Backout link: https://hg.mozilla.org/integration/autoland/rev/19f854ec1c995224cf63dca1a4c5c080bce26918
Assignee | ||
Comment 25•1 month ago
|
||
As it looks like the .dtd test files as used by Marionette were the last ones in the tree that are actually considered to check:
https://searchfox.org/mozilla-central/search?q=&path=.dtd&case=false®exp=false
With moving them out of the product code and the usage of Fluent these days we most likely can now get rid of this particular test.
The other xpcshell failures happen on Android where I didn't actually run tests for. I'll check.
Assignee | ||
Comment 26•1 month ago
|
||
This test is no longer needed given that the Marionette
DTD test file was the only one remaining in the product.
Comment 27•1 month ago
|
||
Comment 28•1 month ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/42c3fb1f104b
https://hg.mozilla.org/mozilla-central/rev/49a944031a5b
Description
•