Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix block text node insertion tests #50861

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

fred-wang
Copy link
Contributor

Fix test block-text-node-insertion-into-(svg)-script-element.html

The `script_elements` map was probably used in the past to test both
HTML and SVG scripts, but now the tests are split into two files (one
for HTML and one for SVG). The map only contains one entry and we
unnecessarily loop over it. Also the SVG file incorrectly checks HTML
scripts, effectively duplicating what the HTML file does. Finally,
one test involves the `text` property, which is only available on
HTML script elements, not SVG script elements.

These tests rely on checkSecurityPolicyViolationEvent() and
checkMessage() to register listeners for "securitypolicyviolation" and
"message" events but they are actually called after the DOM mutations
that triggering these events, so that makes the test less readable and
possibly flaky. Instead:

- We rely on existing async APIs from `support/csp-violations.js` to
  listen for the violation events. The finaly "trigger fail" only
  seems to be used to force a final message, so we remove it.

- We tweak checkMessage() so it accepts a function to execute after
  event registration, similarly to what `support/csp-violations.js`
  APIs do.

See w3c/trusted-types#576

Note: some SVG tests are just copies of the HTML tests and look wrong since
the default policy expects to see "SVGScriptElement text" sinks. We rewrite
this a bit in follow-up PRs.
The `script_elements` map was probably used in the past to test both
HTML and SVG scripts, but now the tests are split into two files (one
for HTML and one for SVG). The map only contains one entry and we
unnecessarily loop over it. Also the SVG file incorrectly checks HTML
scripts, effectively duplicating what the HTML file does. Finally,
one test involves the `text` property, which is only available on
HTML script elements, not SVG script elements.
@fred-wang
Copy link
Contributor Author

This applies on top of #50824

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants