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

Examine tests which are commented out in <GlobalEventHandlers-onclick.html> #571

Closed
mbrodesser-Igalia opened this issue Dec 31, 2024 · 3 comments

Comments

@fred-wang
Copy link
Collaborator

fred-wang commented Jan 3, 2025

These are the tests commented out:

// Trusted Type assignments via property access does not throw.
async_test(t => {
  window.onclickDone2 = t.step_func_done();
  let script = policy.createScript("window.onclickDone2();");
  let el = document.createElement('a');
  el.onclick = script;
  container.appendChild(el);
  el.click();
}, "a.onclick assigned via policy (successful Script transformation).");

// Unsuitable TrustedType assignments do throw.
async_test(t => {
  window.onclickFail3 = t.unreached_func();
  let script = policy_html.createHTML("window.onclickFail3();");
  let el = document.createElement('a');
  try {
    el.onclick = script;
    container.appendChild(el);
    el.click();
  } catch (e) {
    t.done();
  }
  assert_unreached();
}, "a.onclick assigned via an unsuitable policy.");

// So do plain test assignments.
async_test(t => {
  window.onclickFail4 = t.unreached_func();
  let el = document.createElement('a');
  try {
    el.onclick = window.onclickFail4();
    container.appendChild(el);
    el.click();
  } catch (e) {
    t.done();
  }
  assert_unreached();
}, "a.onclick assigned a test string.");

Basically, they verify that setting an event handler IDL attribute to a string or trusted type behaves the same as if we were setting the event handler content attribute.

For the latter (covered by the three first tests), the spec defines attributes change steps that are called from the DOM spec. The PR whatwg/dom#1268 modifies these callers, to add a preliminary conversion from Trusted types to strings.

For the former (covered by the tests commented out), the spec defines the steps to be run by the setter of an event handler IDL attribute, which eventually set eventHandler's value to the given value.

The eventHandler's value can either null, a callback object or an internal raw uncompiled handler. The last one only seems to be used by the "attribute change steps" mentioned above.

So I believe these uncommented tests do not correspond to anything in specs or open PRs and I'd suggest to remove them. If this is really something we want to support, probably the step 1.4.3 for the setter of an event handler IDL attribute should be modified to convert from Trusted types to strings and set the eventHandler's value to an internal raw uncompiled handler with proper value/location, and things should just work as desired.

Incidentally, more comments on these tests:

  • There is a typo a.setAttribte
  • The assert_unreached calls are incorrect, since the code is really executed after the try. I see this is causing assertion failures but the test still passes.
  • Probably cleaner to just do a assert_throws_js(TypeError, () => { ... }) for cases where we expect exceptions to be thrown (and no need to use async test then).

I'll upload a PR.

cc @otherdaniel @lukewarlow @koto

moz-wptsync-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 3, 2025
…minor tweaks.

See w3c/trusted-types#571 (comment)

Differential Revision: https://phabricator.services.mozilla.com/D233186

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1939893
gecko-commit: e058dd4b64b841edcbd3e5b5dfefd4f8a0ee96af
gecko-reviewers: smaug
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Jan 4, 2025
moz-wptsync-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 6, 2025
…minor tweaks.

See w3c/trusted-types#571 (comment)

Differential Revision: https://phabricator.services.mozilla.com/D233186

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1939893
gecko-commit: e058dd4b64b841edcbd3e5b5dfefd4f8a0ee96af
gecko-reviewers: smaug
@fred-wang
Copy link
Collaborator

The proposed changes are done in web-platform-tests/wpt#49910

I believe we can close this issue (I can't do it, my github account does not have proper permission). If we really think we should allow setting a (handler) property by trusted type, then we should probably have a separate spec issue about it and work on something in the lines of what I mentioned above.

@lukewarlow
Copy link
Member

@koto would you be able to grant Fred the same permissions as me please.

i3roly pushed a commit to i3roly/firefox-dynasty that referenced this issue Jan 8, 2025
sadym-chromium pushed a commit to web-platform-tests/wpt that referenced this issue Jan 14, 2025
…minor tweaks.

See w3c/trusted-types#571 (comment)

Differential Revision: https://phabricator.services.mozilla.com/D233186

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1939893
gecko-commit: e058dd4b64b841edcbd3e5b5dfefd4f8a0ee96af
gecko-reviewers: smaug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants